forked from pembo210/Litesight-api
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexpress.js
71 lines (59 loc) · 1.59 KB
/
express.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
/**
* Module dependencies.
*/
var express = require('express');
var config = require('./config');
var path = require('path');
var logger = require('../lib/logger').logger;
module.exports = function(app, historicSync, peerSync) {
//custom middleware
var setHistoric = function(req, res, next) {
req.historicSync = historicSync;
next();
};
var setPeer = function(req, res, next) {
req.peerSync = peerSync;
next();
};
app.set('showStackError', true);
app.set('json spaces', 0);
app.enable('jsonp callback');
app.use(config.apiPrefix, setHistoric);
app.use(config.apiPrefix, setPeer);
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(express.compress());
if (config.enableEmailstore) {
var allowCopayCrossDomain = function(req, res, next) {
if ('OPTIONS' == req.method) {
res.send(200);
res.end();
return;
}
next();
}
app.use(allowCopayCrossDomain);
}
if (config.publicPath) {
var staticPath = path.normalize(config.rootPath + '/../' + config.publicPath);
//IMPORTANT: for html5mode, this line must to be before app.router
app.use(express.static(staticPath));
}
app.use(function(req, res, next) {
app.locals.config = config;
next();
});
//routes should be at the last
app.use(app.router);
//Assume 404 since no middleware responded
app.use(function(req, res) {
res.status(404).jsonp({
status: 404,
url: req.originalUrl,
error: 'Not found'
});
});
};