server.get('/_next/*', (req, reply) => - what it does
Opened this issue · 0 comments
heshamelmasry77 commented
Hey i see you have this
if (dev) {
server.get('/_next/*', (req, reply) =>
app.handleRequest(req.req, reply.res).then(() => {
reply.sent = true;
})
);
}
I would like to know what it does.
this is my server.js
const express = require("express")
const next = require("next")
const port = parseInt(process.env.PORT, 10) || 3000;
const dev = process.env.NODE_ENV !== "production"
const app = next({dev})
const handle = app.getRequestHandler()
app.prepare()
.then(() => {
const server = express();
if (dev) {
server.get('/_next/*', (req, reply) =>
app.handleRequest(req.req, reply.res).then(() => {
reply.sent = true;
})
);
}
server.get("/rooms/", (req, res) => {
const actualPage = "/rooms";
app.render(req, res, actualPage)
});
server.get("/rooms/:location", (req, res) => {
const actualPage = "/rooms";
const queryParams = {location: req.params.location};
app.render(req, res, actualPage, queryParams)
});
server.get("/room/:id", (req, res) => {
const actualPage = "/single-room"
const queryParams = {id: req.params.id}
app.render(req, res, actualPage, queryParams)
});
server.get("/post-room/:edit", (req, res) => {
const actualPage = "/post-room"
const queryParams = {id: req.params.id}
app.render(req, res, actualPage, queryParams)
});
server.get("*", (req, res) => {
return handle(req, res)
});
server.listen(port, err => {
if (err) throw err;
console.log(`> Ready on http://localhost:${port}`);
});
server.setNotFoundHandler((request, reply) =>
app.render404(request.req, reply.res).then(() => {
reply.sent = true;
})
);
next();
})
.catch((ex) => {
console.error(ex.stack)
process.exit(1)
})
thank you