-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
62 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict'
const { PORT = 3001 } = process.env
// const tracer = require('dd-trace')
// tracer.init({ service: 'nextjs-dd-standard', env: 'sam.brenner' })
// console.log(tracer)
// tracer.use('express')
// tracer.use('next', {
// hooks: {
// request: (span, req, res) => {
// console.log(req.url);
// console.log('sending')
// }
// }
// })
const express = require('express')
const { createServer } = require('http')
const { parse } = require('url')
const cookieParser = require('cookie-parser')
const timeout = require('connect-timeout')
const next = require('next')
const nextApp = next({ dir: __dirname, dev: true, hostname: 'localhost' })
const handle = nextApp.getRequestHandler()
const app = express();
app.use(timeout(`2s`));
const server = createServer(app)
nextApp.prepare().then(() => {
console.log('next app ready')
app.get('/hello', async (req, res) => {
const url = parse(req.url, true)
console.log(req.url)
try {
// pretend this throws and we setup an error handler via sentry or other tooling
await handle(req, res, url)
} catch (e) {
}
await handle(req, res, '_error')
})
})
server.listen(PORT, () => {
console.log('listening on ', PORT)
})