Skip to main content

Custom 404 page for a static website


1 comment

  • DevRel

    Just to add a note about doing this within a NodeJS environment: I was able to get a custom 404 handler working by:

    1. Create a 404.js handler with a wildcard route match - I used ExpressJS, YMMV.
    const config = require("platformsh-config").config();
    const express = require('express')
    const app = express()
    app.get('/*', (req, res) => {
        res.status(404).send('Sorry, that page cannot be found.')
    app.listen(config.port, () => {
        console.log(`[INFO]: ExpressJS listening on ${config.port}.`)
    1. Alter app config in to run the 404.js handler script by default, and set passthru to true, to forward any not-found requests to it:
          start: node 404.js
            root: 'build'
            index: ['index.html']
            scripts: false
            allow: true
            passthru: true

    Hope that helps!


Please sign in to leave a comment.