Convert to JavaScript Standard Style

parent 1b255d42
{
"env": {
"es6": true,
"node": true,
"mocha": true
},
"parserOptions": {
"ecmaVersion": 2017
},
"extends": "eslint:recommended",
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
}
// Application hooks that run for every service
const logger = require('./hooks/logger');
const logger = require('./hooks/logger')
module.exports = {
before: {
......@@ -31,4 +31,4 @@ module.exports = {
patch: [],
remove: []
}
};
}
const path = require('path');
const favicon = require('serve-favicon');
const compress = require('compression');
const cors = require('cors');
const helmet = require('helmet');
const logger = require('winston');
const path = require('path')
const favicon = require('serve-favicon')
const compress = require('compression')
const cors = require('cors')
const helmet = require('helmet')
const logger = require('winston')
const feathers = require('@feathersjs/feathers');
const configuration = require('@feathersjs/configuration');
const express = require('@feathersjs/express');
const socketio = require('@feathersjs/socketio');
const feathers = require('@feathersjs/feathers')
const configuration = require('@feathersjs/configuration')
const express = require('@feathersjs/express')
const socketio = require('@feathersjs/socketio')
const middleware = require('./middleware')
const services = require('./services')
const appHooks = require('./app.hooks')
const channels = require('./channels')
const middleware = require('./middleware');
const services = require('./services');
const appHooks = require('./app.hooks');
const channels = require('./channels');
const app = express(feathers());
const app = express(feathers())
// Load app configuration
app.configure(configuration());
app.configure(configuration())
// Enable CORS, security, compression, favicon and body parsing
app.use(cors());
app.use(helmet());
app.use(compress());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(favicon(path.join(app.get('public'), 'favicon.ico')));
app.use(cors())
app.use(helmet())
app.use(compress())
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
app.use(favicon(path.join(app.get('public'), 'favicon.ico')))
// Host the public folder
app.use('/', express.static(app.get('public')));
app.use('/', express.static(app.get('public')))
// Set up Plugins and providers
app.configure(express.rest());
app.configure(socketio());
app.configure(express.rest())
app.configure(socketio())
// Configure other middleware (see `middleware/index.js`)
app.configure(middleware);
app.configure(middleware)
// Set up our services (see `services/index.js`)
app.configure(services);
app.configure(services)
// Set up event channels (see channels.js)
app.configure(channels);
app.configure(channels)
// Configure a middleware for 404s and the error handler
app.use(express.notFound());
app.use(express.errorHandler({ logger }));
app.use(express.notFound())
app.use(express.errorHandler({ logger }))
app.hooks(appHooks);
app.hooks(appHooks)
module.exports = app;
module.exports = app
module.exports = function(app) {
if(typeof app.channel !== 'function') {
module.exports = function (app) {
if (typeof app.channel !== 'function') {
// If no real-time functionality has been configured just return
return;
return
}
app.on('connection', connection => {
// On a new real-time connection, add it to the anonymous channel
app.channel('anonymous').join(connection);
});
app.channel('anonymous').join(connection)
})
app.on('login', (authResult, { connection }) => {
// connection can be undefined if there is no
// real-time connection, e.g. when logging in via REST
if(connection) {
if (connection) {
// Obtain the logged in user from the connection
// const user = connection.user;
// The connection is no longer anonymous, remove it
app.channel('anonymous').leave(connection);
app.channel('anonymous').leave(connection)
// Add it to the authenticated user channel
app.channel('authenticated').join(connection);
app.channel('authenticated').join(connection)
// Channels can be named anything and joined on any condition
// Channels can be named anything and joined on any condition
// E.g. to send real-time events only to admins use
// if(user.isAdmin) { app.channel('admins').join(connection); }
// If the user has joined e.g. chat rooms
// if(Array.isArray(user.rooms)) user.rooms.forEach(room => app.channel(`rooms/${room.id}`).join(channel));
// Easily organize users by email and userid for things like messaging
// app.channel(`emails/${user.email}`).join(channel);
// app.channel(`userIds/$(user.id}`).join(channel);
}
});
})
app.publish((data, hook) => { // eslint-disable-line no-unused-vars
// Here you can add event publishers to channels set up in `channels.js`
......@@ -43,13 +43,13 @@ module.exports = function(app) {
console.log('Publishing all events to all authenticated users. See `channels.js` and https://docs.feathersjs.com/api/channels.html for more information.'); // eslint-disable-line
// e.g. to publish all service events to all authenticated users use
return app.channel('authenticated');
});
return app.channel('authenticated')
})
// Here you can also add service specific event publishers
// e..g the publish the `users` service `created` event to the `admins` channel
// app.service('users').publish('created', () => app.channel('admins'));
// With the userid and email organization from above you can easily select involved users
// app.service('messages').publish(() => {
// return [
......@@ -57,4 +57,4 @@ module.exports = function(app) {
// app.channel(`emails/${data.recipientEmail}`)
// ];
// });
};
}
// A hook that logs service method before, after and error
// See https://github.com/winstonjs/winston for documentation
// about the logger.
const logger = require('winston');
const logger = require('winston')
// To see more detailed messages, uncomment the following line
// logger.level = 'debug';
......@@ -10,14 +10,14 @@ module.exports = function () {
return context => {
// This debugs the service call and a stringified version of the hook context
// You can customize the mssage (and logger) to your needs
logger.debug(`${context.type} app.service('${context.path}').${context.method}()`);
if(typeof context.toJSON === 'function') {
logger.debug('Hook Context', JSON.stringify(context, null, ' '));
logger.debug(`${context.type} app.service('${context.path}').${context.method}()`)
if (typeof context.toJSON === 'function') {
logger.debug('Hook Context', JSON.stringify(context, null, ' '))
}
if (context.error) {
logger.error(context.error);
logger.error(context.error)
}
};
};
}
}
/* eslint-disable no-console */
const logger = require('winston');
const app = require('./app');
const port = app.get('port');
const server = app.listen(port);
const logger = require('winston')
const app = require('./app')
const port = app.get('port')
const server = app.listen(port)
process.on('unhandledRejection', (reason, p) =>
logger.error('Unhandled Rejection at: Promise ', p, reason)
);
)
server.on('listening', () =>
logger.info('Feathers application started on http://%s:%d', app.get('host'), port)
);
)
module.exports = function (app) { // eslint-disable-line no-unused-vars
// Add your custom middleware here. Remember, that
// in Express the order matters
};
}
module.exports = function (app) { // eslint-disable-line no-unused-vars
};
}
const assert = require('assert');
const rp = require('request-promise');
const url = require('url');
const app = require('../src/app');
/* global describe, before, after, it */
const assert = require('assert')
const rp = require('request-promise')
const url = require('url')
const app = require('../src/app')
const port = app.get('port') || 3030;
const getUrl = pathname => url.format({
hostname: app.get('host') || 'localhost',
protocol: 'http',
port,
pathname
});
const port = app.get('port') || 3030
const getUrl = pathname =>
url.format({
hostname: app.get('host') || 'localhost',
protocol: 'http',
port,
pathname
})
describe('Feathers application tests', () => {
before(function(done) {
this.server = app.listen(port);
this.server.once('listening', () => done());
});
before(function (done) {
this.server = app.listen(port)
this.server.once('listening', () => done())
})
after(function(done) {
this.server.close(done);
});
after(function (done) {
this.server.close(done)
})
it('starts and shows the index page', () => {
return rp(getUrl()).then(body =>
assert.ok(body.indexOf('<html>') !== -1)
);
});
return rp(getUrl()).then(body => assert.ok(body.indexOf('<html>') !== -1))
})
describe('404', function() {
describe('404', function () {
it('shows a 404 HTML page', () => {
return rp({
url: getUrl('path/to/nowhere'),
headers: {
'Accept': 'text/html'
Accept: 'text/html'
}
}).catch(res => {
assert.equal(res.statusCode, 404);
assert.ok(res.error.indexOf('<html>') !== -1);
});
});
assert.equal(res.statusCode, 404)
assert.ok(res.error.indexOf('<html>') !== -1)
})
})
it('shows a 404 JSON error without stack trace', () => {
return rp({
url: getUrl('path/to/nowhere'),
json: true
}).catch(res => {
assert.equal(res.statusCode, 404);
assert.equal(res.error.code, 404);
assert.equal(res.error.message, 'Page not found');
assert.equal(res.error.name, 'NotFound');
});
});
});
});
assert.equal(res.statusCode, 404)
assert.equal(res.error.code, 404)
assert.equal(res.error.message, 'Page not found')
assert.equal(res.error.name, 'NotFound')
})
})
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment