Who to register log error 500 in log file
-
Hello
I have a website in ssr mode but when it generates an error 500 we don’t know how to enter the error.
const express = require('express') const compression = require('compression') const ssr = require('quasar-ssr') const extension = require('./extension') const app = express() const port = process.env.PORT || 3000 const host = 'localhost' const backlog = 511 const serve = (path, cache) => express.static(ssr.resolveWWW(path), { maxAge: cache ? 1000 * 60 * 60 * 24 * 30 : 0 }) // gzip app.use(compression({ threshold: 0 })) // serve this with no cache, if built with PWA: if (ssr.settings.pwa) { app.use(ssr.resolveUrl('/service-worker.js'), serve('service-worker.js')) } // serve "www" folder app.use(ssr.resolveUrl('/'), serve('.', true)) // we extend the custom common dev & prod parts here extension.extendApp({ app, ssr }) // this should be last get(), rendering with SSR app.get(ssr.resolveUrl('*'), (req, res) => { res.setHeader('Content-Type', 'text/html') ssr.renderToString({ req, res }, (err, html) => { if (err) { if (err.url) { res.redirect(err.url) } else if (err.code === 404) { // Should reach here only if no "catch-all" route // is defined in /src/routes res.status(404).send('404 | Page Not Found') } else { // Render Error Page or // create a route (/src/routes) for an error page and redirect to it res.status(500).send('500 | Internal Server Error') if (ssr.settings.debug) { console.error(500 on ${req.url}) console.error(err) console.error(err.stack) } } } else { res.send(html) } }) }) app.listen(port, host, backlog, () => { console.log(Server listening at port ${port}) })
How could I improve this configuration to record the logs on the server.
Thanks
-
@jhon You would typically use a logging engine like pino, winston, or something custom. Or, if you run your app through PM2, it would log the console.log by default. The terms above should give you some starting point to Google.