git ssb

0+

Rômulo Alves / website



Tree: ffb059a9465e9ad3d05e45d9090b4beaba053fed

Files: ffb059a9465e9ad3d05e45d9090b4beaba053fed / 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