You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.2 KiB

7 years ago
const app = require('express')();
const swaggerJSDoc = require('swagger-jsdoc');
const swaggerUi = require('express-swaggerize-ui');
const peliasConfig = require( 'pelias-config' ).generate(require('./schema'));
if( peliasConfig.api.accessLog ){
app.use( require( './middleware/access_log' ).createAccessLogger( peliasConfig.api.accessLog ) );
}
7 years ago
var swaggerSpec = swaggerJSDoc(require( './config/swagger'));
app.get('/api-docs.json', function(req, res) {
res.setHeader('Content-Type', 'application/json');
res.send(swaggerSpec);
});
app.use('/api-docs', swaggerUi());
/** ----------------------- pre-processing-middleware ----------------------- **/
app.use( require('./middleware/headers') );
app.use( require('./middleware/cors') );
app.use( require('./middleware/options') );
app.use( require('./middleware/jsonp') );
/** ----------------------- routes ----------------------- **/
7 years ago
const defaultRoutes = require('./routes/default');
defaultRoutes.addRoutes(app);
7 years ago
const v1 = require('./routes/v1');
v1.addRoutes(app, peliasConfig);
/** ----------------------- error middleware ----------------------- **/
app.use( require('./middleware/404') );
app.use( require('./middleware/500') );
7 years ago
module.exports = app;