I m using this script to start my next js app, i cant share whole script, but i need to some help to know:
what is use of compression ? what is use of helmet ? what is use of next({dev}) ?
const express = require('express');
const next = require('next');
const helmet = require('helmet');
const compression = require('compression');
const nextApp = next({ dev });
const nextRequestHandler = routes.getRequestHandler(nextApp);
nextApp.prepare()
.then(() => {
const server = express();
server.use(compression());
server.use(helmet.noSniff());
server.use(helmet.hsts({ preload: true }));
server.use(helmet.hidePoweredBy());
const requestFun = (req, res) => {
const parsedUrl = parse(req.url, true);
const { pathname } = parsedUrl;
//res.setHeader('X-XSS-Protection', '1; mode=block');
if (pathname === 'xyz' || pathname.startsWith('xyz') || pathname.startsWith('xyz' || pathname.startsWith('/_next'))) {
const filePath = join(__dirname, '../public', pathname);
nextApp.serveStatic(req, res, filePath);
} else {
nextRequestHandler(req, res, req.url);
}
}
server.listen(port, (err) => {
if (err) {
throw err;
};
console.log(`Server started on port ${port}`);
})
})
.catch((ex) => {
console.error(ex.stack);
process.exit(1);
});
next()
likely comes from Express which is a Node server framework that most libraries are based on.