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