Skip to content

Commit

Permalink
added @asymmetrik/fhir-gql-schema-utils (#15)
Browse files Browse the repository at this point in the history
chore: Upgraded to use @asymmetrik/fhir-gql-schema-utils, Installed prettier
  • Loading branch information
jgrasso2 authored and Robert-W committed Jan 3, 2019
1 parent 9d79ad3 commit be3b700
Show file tree
Hide file tree
Showing 2,780 changed files with 138,081 additions and 110,675 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"space-infix-ops": 2,
"keyword-spacing": 2,
"space-unary-ops": [2, { "words": true, "nonwords": false }],
"yoda": [2, "never"]
"yoda": [2, "never"],
"no-mixed-spaces-and-tabs": [0, "smart-tabs"]
}
}
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@
"start": "node src/index",
"nodemon": "node src/scripts/nodemon",
"test": "node src/scripts/test --env=jsdom",
"prettier": "prettier \"src/**/*.js\" --write",
"lint": "eslint \"src/**/*.js\""
},
"prettier": {
"trailingComma": "all",
"singleQuote": true
},
"dependencies": {
"@asymmetrik/fhir-gql-schema-utils": "^1.0.1",
"body-parser": "^1.18.3",
"compression": "^1.7.2",
"express": "^4.16.3",
Expand All @@ -34,7 +40,8 @@
"devDependencies": {
"coveralls": "^3.0.2",
"eslint": "^5.1.0",
"jest": "^23.2.0"
"jest": "^23.2.0",
"prettier": "^1.15.3"
},
"jest": {
"verbose": true,
Expand Down
16 changes: 8 additions & 8 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const path = require('path');
*/
const VERSION = {
'1_0_2': '1_0_2',
'3_0_1': '3_0_1'
'3_0_1': '3_0_1',
};

/**
Expand All @@ -21,7 +21,7 @@ const SERVER_CONFIG = {
port: process.env.PORT || 3000,
// Logger configurations
logging: {
level: 'debug'
level: 'debug',
},
// Auth configurations
auth: {
Expand All @@ -31,9 +31,9 @@ const SERVER_CONFIG = {
introspectionUrl: process.env.INTROSPECTION_URL,
strategy: path.posix.resolve('src/strategies/bearer.strategy.js'),
passportOptions: {
session: false
}
}
session: false,
},
},
};

/**
Expand All @@ -45,7 +45,7 @@ const DATE_CONFIG = {
// are different from what's defined in 3.0.1 structure defintions
dateFormat: 'YYYY-MM-DD',
timeFormat: 'HH:mm:ss',
dateTimeFormat: 'YYYY-MM-DDTHH:mm:ss.SSSSZ'
dateTimeFormat: 'YYYY-MM-DDTHH:mm:ss.SSSSZ',
};

/**
Expand All @@ -57,12 +57,12 @@ const RESOURCE_CONFIG = {
// base folder for all the resources relative to src
resourceBase: 'resources',
// Path is relative to version folder under resources
profilesRelativePath: 'profiles/**/index.js'
profilesRelativePath: 'profiles/**/index.js',
};

module.exports = {
RESOURCE_CONFIG,
SERVER_CONFIG,
DATE_CONFIG,
VERSION
VERSION,
};
55 changes: 32 additions & 23 deletions src/lib/server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const { configureRoutes, parseVersionFromUrl } = require('../utils/router.utils');
const {
configureRoutes,
parseVersionFromUrl,
} = require('../utils/router.utils');
const { VERSION, RESOURCE_CONFIG } = require('../config');
const errorUtils = require('../utils/error.utils');
const compression = require('compression');
Expand All @@ -12,8 +15,7 @@ const http = require('http');
const fs = require('fs');

class Server {

constructor (config = {}) {
constructor(config = {}) {
// Store the config
this.config = config;

Expand All @@ -27,22 +29,23 @@ class Server {
this.env = {
IS_PRODUCTION: process.env.NODE_ENV === 'production',
USE_HTTPS: config.ssl && config.ssl.key && config.ssl.cert,
AUTHENTICATION: false
AUTHENTICATION: false,
};
// return self for chaining
return this;
}

// Initialize a database connection
initializeDatabaseConnection (options = {}) {
// eslint-disable-next-line no-unused-vars
initializeDatabaseConnection(options = {}) {
// Store the db on this somehow

// return self for chaining
return this;
}

// Configure session
configureSession (session) {
configureSession(session) {
// Session config can come from the core config as well, let's handle both cases
let { sessionStore } = this.config;
// If a session was passed in the config, let's use it
Expand All @@ -54,7 +57,7 @@ class Server {
}

// Configure middleware
configureMiddleware () {
configureMiddleware() {
// Enable stack traces
this.app.set('showStackError', !this.env.IS_PRODUCTION);
// Add compression
Expand All @@ -67,7 +70,7 @@ class Server {
}

// Configure helmet
configureHelmet (helmetConfig) {
configureHelmet(helmetConfig) {
/**
* The following headers are turned on by default:
* - dnsPrefetchControl (Controle browser DNS prefetching). https://helmetjs.github.io/docs/dns-prefetch-control
Expand All @@ -78,15 +81,19 @@ class Server {
* - noSniff (prevent clients from sniffing MIME type). https://helmetjs.github.io/docs/dont-sniff-mimetype
* - xssFilter (adds small XSS protections). https://helmetjs.github.io/docs/xss-filter/
*/
this.app.use(helmet(helmetConfig || {
// Needs https running first
hsts: this.env.USE_HTTPS
}));
this.app.use(
helmet(
helmetConfig || {
// Needs https running first
hsts: this.env.USE_HTTPS,
},
),
);
// return self for chaining
return this;
}

configurePassport () {
configurePassport() {
let { auth } = this.config;
// Only add passport if we have valid configurations
if (auth.strategy && auth.name) {
Expand All @@ -101,7 +108,7 @@ class Server {
}

// Setup a public directory for static assets
setPublicDirectory (publicDir = '') {
setPublicDirectory(publicDir = '') {
// Public config can come from the core config as well, let's handle both cases
let { publicDirectory } = this.config;

Expand All @@ -113,20 +120,20 @@ class Server {
}

// Setup profile routes
setProfileRoutes () {
setProfileRoutes() {
this.logger.info('Loading GraphQL schemas and setting routes');
// Pass this instance so I can grab the express app and any config
// that may or may not be necessary for the router utils
configureRoutes(this, {
resourceConfig: RESOURCE_CONFIG,
versions: Object.keys(VERSION)
versions: Object.keys(VERSION),
});
// return self for chaining
return this;
}

// Setup error routes
setErrorRoutes () {
setErrorRoutes() {
// Generic catch all error handler
// Errors should be passed through with next
this.app.use((err, req, res, next) => {
Expand Down Expand Up @@ -161,23 +168,25 @@ class Server {
}

// Start the server
listen (port = process.env.PORT, callback) {
listen(port = process.env.PORT, callback) {
let { ssl } = this.config;

// Create our server
this.app = !this.env.USE_HTTPS
? http.createServer(this.app)
: https.createServer({
key: fs.readFileSync(ssl.key),
cert: fs.readFileSync(ssl.cert)
}, this.app);
: https.createServer(
{
key: fs.readFileSync(ssl.key),
cert: fs.readFileSync(ssl.cert),
},
this.app,
);

// Listen
this.app.listen(port, callback);

return this;
}

}

module.exports = Server;
8 changes: 4 additions & 4 deletions src/lib/winston.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ const winston = require('winston');
* @name exports
* @summary Application logger. Add more transports as necessary
*/
module.exports = function (config = {}) {
module.exports = function(config = {}) {
return winston.createLogger({
transports: [
new winston.transports.Console({
level: config.level,
colorize: true,
timestamp: true
})
]
timestamp: true,
}),
],
});
};
4 changes: 2 additions & 2 deletions src/middleware/authentication.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const passport = require('passport');
* @name exports
* @summary Middleware function for authentication
*/
module.exports = function authenticationMiddleware (server) {
let auth = server && server.config && server.config.auth || {};
module.exports = function authenticationMiddleware(server) {
let auth = (server && server.config && server.config.auth) || {};
let env = server && server.env;

return env && env.AUTHENTICATION
Expand Down
17 changes: 7 additions & 10 deletions src/middleware/authentication.middleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,23 @@ let authServer = {
auth: {
name: 'test',
passportOptions: {
session: false
}
}
session: false,
},
},
},
env: {
AUTHENTICATION: true
}
AUTHENTICATION: true,
},
};

// Mock config for no authentication
let noAuthServer = {
env: {
AUTHENTICATION: false
}
AUTHENTICATION: false,
},
};


describe('Authentication Middleware Test', () => {

test('should return noop middleware when no server configuration is provided ', () => {
let middleware = authenticationMiddleware();
expect(middleware).toBe(noopMiddleware);
Expand All @@ -46,5 +44,4 @@ describe('Authentication Middleware Test', () => {
expect(mock.calls[0][0]).toBe(authServer.config.auth.name);
expect(mock.calls[0][1]).toBe(authServer.config.auth.passportOptions);
});

});
2 changes: 1 addition & 1 deletion src/middleware/noop.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
* @example
* route.use(server.env.AUTHENTICATION ? authMiddleware : noopMiddleware)
*/
module.exports = function noopMiddleware (req, res, next) {
module.exports = function noopMiddleware(req, res, next) {
return next();
};
2 changes: 0 additions & 2 deletions src/middleware/noop.middleware.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const noopMiddleware = require('./noop.middleware');

describe('Noop Middleware Test', () => {

test('should call next with no arguments', () => {
let next = jest.fn();
// req and res are never used, so we can safely pass in null for those
Expand All @@ -11,5 +10,4 @@ describe('Noop Middleware Test', () => {
// Next should not be called with any arguments
expect(next.mock.calls[0].length).toBe(0);
});

});
Loading

0 comments on commit be3b700

Please sign in to comment.