-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
43 lines (37 loc) · 999 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
import sirv from 'sirv';
import polka from 'polka';
import compression from 'compression';
import bodyParser from 'body-parser';
import dotenv from 'dotenv';
import beeline from 'honeycomb-beeline';
import * as sapper from '@sapper/server';
dotenv.config()
beeline({
writeKey: process.env.honeycomb_write_key,
dataset: "nikolas.ws.instrumentation",
serviceName: "Polka Server"
})
const uuid = () => {
let a = (Math.random() * 46656) | 0
let b = (Math.random() * 46656) | 0
a = ("000" + a.toString(36)).slice(-3)
b = ("000" + b.toString(36)).slice(-3)
return `${a}${b}`
}
const { PORT, NODE_ENV } = process.env;
const dev = NODE_ENV === 'development';
const app = polka() // You can also use Express
.use(
bodyParser.json(),
compression({ threshold: 0 }),
sirv('static', { dev }),
sapper.middleware({
session: (req, res) => ({
id: uuid()
})
})
)
.listen(PORT, err => {
if (err) console.log('error', err);
});
export default app