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.

58 lines
1.9 KiB

var app = require('express')();
var peliasConfig = require( 'pelias-config' ).generate().api;
if( peliasConfig.accessLog ){
app.use( require( './middleware/access_log' )( peliasConfig.accessLog ) );
}
/** ----------------------- middleware ----------------------- **/
app.use( require('./middleware/headers') );
app.use( require('./middleware/cors') );
app.use( require('./middleware/jsonp') );
10 years ago
/** ----------------------- sanitisers ----------------------- **/
var sanitisers = {};
10 years ago
sanitisers.doc = require('./sanitiser/doc');
sanitisers.suggest = require('./sanitiser/suggest');
sanitisers.search = require('./sanitiser/search');
sanitisers.coarse = require('./sanitiser/coarse');
sanitisers.reverse = require('./sanitiser/reverse');
10 years ago
/** ----------------------- controllers ----------------------- **/
var controllers = {};
controllers.index = require('./controller/index');
10 years ago
controllers.doc = require('./controller/doc');
controllers.search = require('./controller/search');
10 years ago
/** ----------------------- routes ----------------------- **/
// api root
10 years ago
app.get( '/', controllers.index() );
10 years ago
// doc API
app.get( '/doc', sanitisers.doc.middleware, controllers.doc() );
// suggest APIs
10 years ago
app.get( '/suggest', sanitisers.search.middleware, controllers.search() );
app.get( '/suggest/nearby', sanitisers.suggest.middleware, controllers.search() );
app.get( '/suggest/coarse', sanitisers.coarse.middleware, controllers.search() );
// search APIs
app.get( '/search', sanitisers.search.middleware, controllers.search() );
app.get( '/search/coarse', sanitisers.coarse.middleware, controllers.search() );
10 years ago
// reverse API
app.get( '/reverse', sanitisers.reverse.middleware, controllers.search(undefined, require('./query/reverse')) );
/** ----------------------- error middleware ----------------------- **/
app.use( require('./middleware/404') );
9 years ago
app.use( require('./middleware/408') );
app.use( require('./middleware/500') );
9 years ago
module.exports = app;