git ssb

0+

Rômulo Alves / website



Tree: dc22d9e889bb033f0b468f7e989348326056b9f8

Files: dc22d9e889bb033f0b468f7e989348326056b9f8 / server.js

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