-
Notifications
You must be signed in to change notification settings - Fork 8
/
server.js
45 lines (38 loc) · 982 Bytes
/
server.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
const ReactTools = require('react-tools');
const server = ({engines: {express: app}}) => ({
mount() {
function corsPost(req, res) {
console.log('cors post', req.url);
let b = '';
req.setEncoding('utf8');
req.on('data', s => {
b += s;
});
req.on('end', () => {
const js = ReactTools.transform(b);
console.log('cors client transform', {
req: b,
res: js,
});
res.type('application/javascript');
res.send(js);
});
}
app.post('/corsPlugin', corsPost);
this._cleanup = () => {
function removeMiddlewares(route, i, routes) {
if (route.handle.name === 'corsPost') {
routes.splice(i, 1);
}
if (route.route) {
route.route.stack.forEach(removeMiddlewares);
}
}
app._router.stack.forEach(removeMiddlewares);
};
},
unmount() {
this._cleanup();
},
});
module.exports = server;