Files: 05da29162cd94001b87a1366246df608c8a7fa4d / server.js
887 bytesRaw
1 | const { createServer } = require('http'); |
2 | const { parse } = require('url'); |
3 | const { createReadStream } = require('fs'); |
4 | const { join } = require('path'); |
5 | const next = require('next'); |
6 | |
7 | |
8 | const port = parseInt(process.env.PORT, 10) || 3000; |
9 | const dev = process.env.NODE_ENV !== 'production'; |
10 | const app = next({ dev }); |
11 | const handle = app.getRequestHandler(); |
12 | |
13 | app.prepare() |
14 | .then(() => { |
15 | createServer((req, res) => { |
16 | const parsedUrl = parse(req.url, true); |
17 | const { pathname, query } = parsedUrl; |
18 | |
19 | if (pathname === '/.well-known/dat') { |
20 | res.writeHead(200, { 'Content-Type': 'text/plain' }); |
21 | |
22 | return createReadStream(join(__dirname, pathname)).pipe(res); |
23 | } |
24 | |
25 | return handle(req, res, parsedUrl); |
26 | }).listen(port, err => { |
27 | if (err) { |
28 | throw err; |
29 | } |
30 | |
31 | console.log(`> Ready on http://localhost:${port}`); |
32 | }); |
33 | }); |
Built with git-ssb-web