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