-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
44 lines (41 loc) · 1.23 KB
/
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
/* eslint no-console: 0 */
const jsdom = require('jsdom');
const app = require('./app');
module.exports.handle = (request, context, callback) => {
const route = request.pathParameters && request.pathParameters.route || '';
const docType = '<!DOCTYPE html>';
const staticRoot = process.env.STATIC_ROOT || '';
jsdom.env({
url: process.env.API_HOST + route,
html: `
${docType}
<html>
<head>
<base href="/dev/view/" />
<link rel="shortcut icon" href="${staticRoot}/favicon.ico" type="image/x-icon">
<link rel="icon" href="${staticRoot}/favicon.ico" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="${staticRoot}/css/styles.css" />
</head>
<body>
<script src="${staticRoot}/bundle.js"></script>
</body>
</html>
`,
done: (error, window) => {
if(error) {
callback(error);
}
else {
app(window).then(() => {
callback(null, {
statusCode: 200,
headers: {
'content-type': 'text/html'
},
body: docType + window.document.documentElement.outerHTML
});
}).catch(err => console.error(err));
}
}
});
}