koopjs / FeatureServer

An open source Geoservices Implementation (deprecated)
https://geoservices.github.io
Other
104 stars 32 forks source link

custom html page for featureserver route errors #113

Closed keithfraley closed 6 years ago

keithfraley commented 6 years ago

where / how can I display a custom error page when a user types in the wrong url?

right now it states 'Cannot GET /'

rgwozdz commented 6 years ago

The Cannot GET / response doesn't come from FeatureServer, but from Express itself (the underlying webserver framework of Koop). If you want to customize handling of 404s you could attach a handler after all your provider registrations:

koop.server.use(function (req, res, next) {
    res.status(404).send(`<!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="utf-8">
            <title>Error</title>
        </head>
        <body>
            <pre>Cannot GET /etrics/views/day/FeatureServer/0/query</pre>
            <p>Customize your HTML!!!</p>
        </body>
    </html>`)
})

You can get fancy by using HTML templates and rendering them - check the Express docs.