Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
unignore api config
Browse files Browse the repository at this point in the history
  • Loading branch information
p-mcgowan@homebot committed Dec 5, 2017
1 parent 9437ca9 commit e434d9b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,5 +1,5 @@
node_modules
config.js
./config.js

public

Expand Down
51 changes: 51 additions & 0 deletions api/config.js
@@ -0,0 +1,51 @@
const join = require('path').join;
const logFile = require('fs').createWriteStream(join(__dirname, './logs/api.txt'), { flags: 'w' });
const ospreyAuth = require('./modules/security.js');
const util = require('util');

const config = {
spec: join(__dirname, './spec/hr-fhir-api.raml'),
mountpoint: '/v1',
ospreyConfig: {
server: {
notFoundHandler: false
},
security: ospreyAuth,
disableErrorInterception: true
},
ramlOnError: (error, request, response, next) => {
if (error) {
// More granularity later, just 422 for now
if (process.env.NODE_ENV !== 'production') {
config.log(error);
console.trace(error);
return response.status(422).json({ message: 'Bad request', status: 422, error });
} else {
return response.status(422).json({ message: 'Bad request', status: 422, error: error.message });
}
}
return next();
},
ramlOnNotFound: (request, response, next) => {
if (request.resourcePath) {
return next();
}
return response.status(404).json({ message: 'Not found', status: 404 });
},
log: function() {
let where;
try { throw Error() } catch (err) { where = err.stack; }
logFile.write(`${where}\n` + util.inspect(arguments, { depth: null, colors: true }) + '\n');
},
error: (response, error) => {
const message = { message: 'Something went wrong' };
if (process.env.NODE_ENV !== 'production') {
config.log(error)
console.trace(error);
message.error = error;
}
return response.status(500).json(message);
}
};

module.exports = config;

0 comments on commit e434d9b

Please sign in to comment.