question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Specify a default 404 file

See original GitHub issue

Can we get an option to set a 404 file for requests that 404? It can definitely default to false, but if set to a file path then serve that file path in the body. This would be especially helpful for almost static sites being run by koa and koa middleware.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
michielbdejongcommented, Mar 31, 2020

FWIW, not sure if this is the best answer, but I got this working with:

const Koa = require("koa");
const koaSend = require("koa-send");
const koaStatic = require("koa-static");

const app = new Koa();
app.use(koaStatic("./public/", {}));
app.use(async ctx => {
  if (ctx.status === 404) {
    await koaSend(ctx, "index.html", { root: "./public/" });
  }
});
app.listen(3000);
1reaction
mashhoodrcommented, May 13, 2018

@silenceisgolden can you please share the middleware you wrote for this, did you use koa-send to manually send serve the files on 404?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Create a Great Custom 404 Error Page (with Examples)
Step 1: Design the Page · Step 2: Configure the Server · Step 3: Test Your Configuration · Step 4: Track 404 Sessions...
Read more >
How to Set a Custom 404 Page With .htaccess
Create or Modify a Custom 404 Page via .htaccess · Login to your cPanel. · Under the Files section click on File Manager....
Read more >
A Beginners Guide to Custom 404 Pages - LCN.com
A Beginners Guide to Custom 404 Pages · Leverage on SEO benefits. Customise the error page to make it resemble the other pages...
Read more >
Creating an HTML 404! Error Web Page - Udacity
Step 1: Create an HTML Landing Web Page · Step 2: Tell the Server to Use Your HTML 404! Error Page · Step...
Read more >
How to Set Up A Custom 404 File Not Found Page
How to Set Up A Custom 404 File Not Found Page · Step One: Creating/Modifying the .htaccess File · Step Two: Creating Your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found