-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
32 lines (28 loc) · 1.06 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
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
module.exports = function registerWebpackMiddlewareForRestify(restifyApp, config) {
const devMiddlewareInstance = webpackDevMiddleware(config.compiler, config.webpackDevConfig);
const hotMiddlewareInstance = webpackHotMiddleware(config.compiler, config.webpackHotConfig);
function webpackDevMiddlewareForRestify(req, res, next) {
// stub restify methods as used within `webpack-dev-middleware`
const restifyTransport = {
setHeader(key, val) {
res.setHeader(key, val);
},
send(content) {
res.charSet('utf-8');
res.writeHead(this.statusCode || 200, {
'Content-Length': Buffer.byteLength(content),
});
res.write(content);
res.end();
},
end() {
return;
},
};
devMiddlewareInstance(req, restifyTransport, next);
}
restifyApp.use(webpackDevMiddlewareForRestify);
restifyApp.get(config.webpackHotConfig.path, hotMiddlewareInstance);
}