2018-09-03 02:03:23 -05:00
|
|
|
const {invokeHookSerial} = require('@truss/truss');
|
|
|
|
|
|
|
|
const {Responder} = require('./response.dev');
|
|
|
|
|
2018-09-08 22:56:39 -05:00
|
|
|
let responder = new Responder();
|
|
|
|
responder.start();
|
2018-09-03 02:03:23 -05:00
|
|
|
|
|
|
|
module.exports = () => ({
|
|
|
|
|
|
|
|
'truss/http-get': (action) => {
|
|
|
|
const {payload: {headers}} = action;
|
|
|
|
|
|
|
|
delete headers.host;
|
|
|
|
delete headers.connection;
|
|
|
|
|
2018-09-08 22:56:39 -05:00
|
|
|
return responder.respond(action).then(({html, headers: resHeaders}) => {
|
2018-09-03 02:03:23 -05:00
|
|
|
return invokeHookSerial('truss/web-response', {
|
|
|
|
status: 200,
|
2018-09-08 22:56:39 -05:00
|
|
|
headers: {...defaultResponseHeaders(), ...resHeaders},
|
2018-09-03 02:03:23 -05:00
|
|
|
html,
|
|
|
|
}, headers);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
'truss/schema': () => {
|
|
|
|
return {executors: ['truss/http-get']};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-09-08 22:56:39 -05:00
|
|
|
function defaultResponseHeaders() {
|
2018-09-03 02:03:23 -05:00
|
|
|
return {
|
2018-09-08 22:56:39 -05:00
|
|
|
date: (new Date()).toUTCString(),
|
|
|
|
connection: 'keep-alive',
|
2018-09-03 02:03:23 -05:00
|
|
|
};
|
|
|
|
}
|
2018-09-08 22:56:39 -05:00
|
|
|
|
|
|
|
if (module.hot) {
|
|
|
|
module.hot.accept('./response.dev', () => {
|
|
|
|
responder.stop();
|
|
|
|
responder = new require('./response.dev').Responder();
|
|
|
|
responder.start();
|
|
|
|
});
|
|
|
|
}
|