code cleanup

Signed-off-by: Alexis Tyler <xo@wvvw.me>
This commit is contained in:
Alexis Tyler
2019-07-07 16:12:00 +09:30
parent 2838b5384b
commit d2522c574c
3 changed files with 16 additions and 19 deletions

View File

@@ -29,12 +29,12 @@ $injector.registerImports([
'graphql',
'deepmerge',
'stoppable'
], module);
]);
// Register modules that need require and not import
$injector.registerRequires([
'graphql'
], module);
]);
// Register the imported modules with custom names.
$injector.registerImports({
@@ -45,7 +45,7 @@ $injector.registerImports({
GraphQLLong: 'graphql-type-long',
GraphQLUUID: 'graphql-type-uuid',
gql: 'graphql-tag'
}, module);
});
// Register all of the single js files as modules.
$injector.registerPath([

View File

@@ -10,7 +10,7 @@
* all copies or substantial portions of the Software.
*/
/**
/**
* The Graphql server.
*/
module.exports = function ($injector, fs, net, express, config, log, getEndpoints, stoppable) {
@@ -26,17 +26,17 @@ module.exports = function ($injector, fs, net, express, config, log, getEndpoint
graphApp.applyMiddleware({ app });
// List all endpoints at start of server
app.get('/', (req, res, next) => {
app.get('/', (_, res) => {
return res.send(getEndpoints(app));
});
// Handle errors by logging them and returning a 500.
app.use(function (err, req, res, next) {
log.error(err);
if (err.stack) {
err.stackTrace = err.stack;
app.use(function (error, _, res, _) {
log.error(error);
if (error.stack) {
error.stackTrace = error.stack;
}
res.status(error.status || 500).send(err);
res.status(error.status || 500).send(error);
});
// Return an object with start and stop methods.
@@ -44,9 +44,9 @@ module.exports = function ($injector, fs, net, express, config, log, getEndpoint
start() {
server = stoppable(app.listen(port, () => {
// Downgrade process user to owner of this file
return fs.stat(__filename, (err, stats) => {
if (err) {
throw err;
return fs.stat(__filename, (error, stats) => {
if (error) {
throw error;
}
return process.setuid(stats.uid);
@@ -92,9 +92,9 @@ module.exports = function ($injector, fs, net, express, config, log, getEndpoint
},
stop() {
// Stop the server from accepting new connections and close existing connections
return server.close(err => {
if (err) {
log.error(err);
return server.close(error => {
if (error) {
log.error(error);
// Exit with error (code 1)
// eslint-disable-next-line
process.exit(1);

View File

@@ -10,8 +10,5 @@
* all copies or substantial portions of the Software.
*/
// Set process title
process.title = require('./package.json').name.split('/')[1];
// Boot app
require('./app');