forked from ember-fastboot/ember-cli-fastboot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (27 loc) · 840 Bytes
/
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
var bodyParser = require('body-parser');
var FastBootExpressMiddleware = require('@gaurav9576/fastboot-express-middleware');
var FastBoot = require('@gaurav9576/fastboot');
module.exports = {
name: 'post-middleware',
serverMiddleware: function(options) {
var app = options.app;
app.use(bodyParser.text());
app.use(function(req, resp, next) {
var broccoliHeader = req.headers['x-broccoli'];
var outputPath = broccoliHeader['outputPath'];
if (req.method === 'POST') {
if (!this.fastboot) {
this.fastboot = new FastBoot({
distPath: outputPath
});
}
var fastbootMiddleware = FastBootExpressMiddleware({
fastboot: this.fastboot
});
fastbootMiddleware(req, resp, next);
} else {
next();
}
});
}
};