This repository has been archived by the owner on Jan 13, 2021. It is now read-only.
forked from carolineBda/compoxure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (36 loc) · 1.71 KB
/
index.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
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var ware = require('ware');
module.exports = function(config, eventHandler, optionsTransformer) {
eventHandler = eventHandler || {};
eventHandler.logger = eventHandler.logger || function() {};
eventHandler.stats = eventHandler.stats || function() {};
optionsTransformer = optionsTransformer || function(req, options, next) { next(null, options); };
var backendProxyMiddleware = require('./src/middleware/proxy')(config, eventHandler, optionsTransformer);
var cacheMiddleware = require('reliable-get/CacheMiddleware')(config);
var selectBackend = require('./src/middleware/backend')(config);
var rejectUnsupportedMediaType = require('./src/middleware/mediatypes');
var passThrough = require('./src/middleware/passthrough')(config);
var interrogateRequest = require('./src/middleware/interrorgator')(config, eventHandler);
var cleanInvalidUri = require('./src/middleware/invalidurl')(eventHandler);
var dropFavIcon = require('./src/middleware/favicon');
var middleware = ware()
.use(cleanInvalidUri)
.use(dropFavIcon)
.use(cacheMiddleware)
.use(interrogateRequest)
.use(selectBackend)
.use(rejectUnsupportedMediaType)
.use(passThrough)
.use(cookieParser)
.use(bodyParser.text({type: 'text/compoxure'}))
.use(backendProxyMiddleware);
return function(req, res) {
middleware.run(req, res, function(err) {
if(err) {
// Just end fast - headers sent above if needed.
res.end('');
}
});
}
};