ironbar-persea/actions.js

39 lines
753 B
JavaScript
Raw Permalink Normal View History

2018-09-03 02:03:23 -05:00
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 = () => ({
2019-03-05 23:20:26 -06:00
'@truss/http-get': async (action) => {
const {html, headers} = await responder.respond(action);
return {
status: 200,
headers: {
...defaultResponseHeaders(),
...headers
},
response: html,
};
2018-09-03 02:03:23 -05:00
},
2019-03-05 23:20:26 -06:00
'@truss/schema': () => ({
executors: ['@truss/http-get'],
}),
2018-09-03 02:03:23 -05:00
});
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();
});
}