git ssb

0+

Rômulo Alves / website



Tree: 5bb525da770fe1c598313238d544b389e0fabaaf

Files: 5bb525da770fe1c598313238d544b389e0fabaaf / server.js

925 bytesRaw
1require('@zeit/next-preact/alias')();
2
3const { createServer } = require('http');
4const { parse } = require('url');
5const { createReadStream } = require('fs');
6const { join } = require('path');
7const next = require('next');
8
9const port = parseInt(process.env.PORT, 10) || 3000;
10const dev = process.env.NODE_ENV !== 'production';
11const app = next({ dev });
12const handle = app.getRequestHandler();
13
14app.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