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.

50 lines
1.5 KiB

var app = require('express')();
/** ----------------------- middleware ----------------------- **/
app.use( require('./middleware/toobusy') ); // should be first
app.use( require('./middleware/headers') );
app.use( require('./middleware/cors') );
app.use( require('./middleware/jsonp') );
10 years ago
/** ----------------------- sanitisers ----------------------- **/
var sanitisers = {};
sanitisers.get = require('./sanitiser/get');
sanitisers.suggest = require('./sanitiser/suggest');
sanitisers.search = sanitisers.suggest;
sanitisers.reverse = require('./sanitiser/reverse');
10 years ago
/** ----------------------- controllers ----------------------- **/
var controllers = {};
controllers.index = require('./controller/index');
controllers.get = require('./controller/get');
10 years ago
controllers.suggest = require('./controller/suggest');
controllers.search = require('./controller/search');
10 years ago
/** ----------------------- routes ----------------------- **/
// api root
10 years ago
app.get( '/', controllers.index() );
// get doc API
app.get( '/get', sanitisers.get.middleware, controllers.get() );
// suggest API
app.get( '/suggest', sanitisers.suggest.middleware, controllers.suggest() );
// search API
app.get( '/search', sanitisers.search.middleware, controllers.search() );
// reverse API
app.get( '/reverse', sanitisers.reverse.middleware, controllers.search(undefined, require('./query/reverse')) );
/** ----------------------- error middleware ----------------------- **/
app.use( require('./middleware/404') );
app.use( require('./middleware/500') );
module.exports = app;