nope/lib/open-api/customServer.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-11-05 17:02:29 +00:00
// server.js
const { createServer } = require('http')
const { parse,format } = require('url')
const next = require('next')
const join = require('path').join
const dev = process.env.NODE_ENV !== 'production'
const app = next({
dev,
useFileSystemPublicRoutes: false,
});
const handle = app.getRequestHandler()
const staticFiles = ['/hello']
app.prepare().then(() => {
const server = require('express')();
server.listen(3000, 'localhost', () => {
server.get('*', (req,res) => {
const { pathname, query } = parse(req.url, true);
if (staticFiles.indexOf(pathname) > -1) {
const path = join(__dirname, "..", pathname);
console.log(path)
// return handle(req,res,path)
// return app.serveStatic(req, res, path);
return res.redirect(
format({
pathname: path,
query,
}),
);
}
return handle(req,res)
})
});
})