Skip to content

Commit 2be25c5

Browse files
committed
Add server
1 parent 97c14af commit 2be25c5

File tree

5 files changed

+791
-415
lines changed

5 files changed

+791
-415
lines changed

handlers/index.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
'use strict'
2+
3+
const { gzipSync } = require('zlib')
4+
5+
const cdn = process.env.CDN || 'http://localhost:8081'
6+
const version = process.env.VERSION || ''
7+
8+
const createContent = root => `
9+
<!doctype html>
10+
<html class="no-js" lang="">
11+
<head>
12+
<meta charset="utf-8">
13+
<meta http-equiv="x-ua-compatible" content="ie=edge">
14+
<title></title>
15+
<meta name="description" content="">
16+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
17+
<link rel="stylesheet" href="${root}/index.css">
18+
</head>
19+
<body>
20+
<div id="root"></div>
21+
<script src="${root}/index.js"></script>
22+
</body>
23+
`
24+
25+
const createBody = () => {
26+
const root = [cdn, version].filter(x => x).join('/')
27+
const content = createContent(root)
28+
const buffer = gzipSync(content)
29+
return buffer.toString('base64')
30+
}
31+
32+
const createResponse = () => ({
33+
headers: {
34+
'content-type': [{
35+
key: 'content-type',
36+
value: 'text/html; charset=utf-8'
37+
}],
38+
'content-encoding': [{
39+
key: 'content-encoding',
40+
value: 'gzip'
41+
}]
42+
},
43+
body: createBody(),
44+
bodyEncoding: 'base64',
45+
status: '200',
46+
statusDescription: 'OK'
47+
})
48+
49+
let response = null
50+
51+
exports.createResponse = createResponse
52+
53+
exports.handler = (event, context, callback) => {
54+
if (response === null) response = createResponse()
55+
callback(null, response)
56+
}

0 commit comments

Comments
 (0)