const dev = process.env.NODE_ENV !== 'production'; if (!dev) { require('@zeit/next-preact/alias')(); } const { createServer } = require('http'); const { parse } = require('url'); const { createReadStream } = require('fs'); const { join } = require('path'); const next = require('next'); const port = parseInt(process.env.PORT, 10) || 3000; const app = next({ dev }); const handle = app.getRequestHandler(); app.prepare() .then(() => { createServer((req, res) => { const parsedUrl = parse(req.url, true); const { pathname, query } = parsedUrl; if (pathname === '/.well-known/dat') { res.writeHead(200, { 'Content-Type': 'text/plain' }); return createReadStream(join(__dirname, pathname)).pipe(res); } return handle(req, res, parsedUrl); }).listen(port, err => { if (err) { throw err; } console.log(`> Ready on http://localhost:${port}`); }); });