forked from seanmtracey/CineList-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
55 lines (43 loc) · 1.33 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const debug = require('debug')('cinelist:app');
const express = require('express');
const path = require('path');
const preload = require('./bin/lib/preload');
const app = express();
app.all('*', function(req, res, next) {
res.set('Access-Control-Allow-Origin', '*');
res.set('Access-Control-Allow-Methods', 'GET, POST');
res.set('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type');
next();
});
// uncomment after placing your favicon in /public
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static('documentation'));
app.get('/__gtg', (req, res) => res.end());
app.use('/check', require('./routes/check'));
app.use('/get', require('./routes/get'));
app.use('/search', require('./routes/search'));
preload();
// catch 404 and forward to error handler
app.use(function(req, res, next) {
res.status(404);
res.end();
});
// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
debug('Stack err:', err);
res.status(err.status || 500);
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.json({
status : err.status,
message : `Sorry, an error occurred.`
});
});
module.exports = app;