Navigation

    Quasar Framework

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Who to register log error 500 in log file

    Framework
    2
    2
    11
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      jhon last edited by

      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

      beets 1 Reply Last reply Reply Quote 0
      • beets
        beets @jhon last edited by

        @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.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post