Git Product home page Git Product logo

When trying to render page I get ERROR { Error: Your middleware did not return anything to the user. This normally happens when no route was matched or if the router did not reply with anything. about server HOT 5 CLOSED

AdamCollins avatar AdamCollins commented on June 3, 2024
When trying to render page I get ERROR { Error: Your middleware did not return anything to the user. This normally happens when no route was matched or if the router did not reply with anything.

from server.

Comments (5)

franciscop avatar franciscop commented on June 3, 2024

Thanks for the complete bug report, I'll try to reproduce later. This does seems like a server.js bug.

from server.

franciscop avatar franciscop commented on June 3, 2024

Hi @AdamCollins, unfortunately I couldn't reproduce the issue and it works fine for me. Could you please put your package.json and copy/paste the full error? I suspect one of these 3 issues might be happening:

  • EJS is not installed (it has to be installed manually) -> npm install ejs. This will make the route throw an error, so it will not render anything and so you'll get this issue.
  • The EJS template is not in the views folder, which will make an error similar to the one above. This can be changed with the views option if you want.
  • Your browser is requesting a different resource like favicon.ico, which will not be found. To debug this, add an extra route that does this to see if there's any extra request that you are not intending to make:
const server = require("server");
const { get, error } = server.router;
const { render, status } = server.reply;

server([
  ctx => {
    console.log(ctx.method, ctx.url);
  },
  get("/", ctx => render("index.ejs"))
]);

There might be some other issue, but these 3 are the ones I'd check for first. I created a repository with working code. Is there anything different from your code?

from server.

franciscop avatar franciscop commented on June 3, 2024

BTW I strongly believe it is the 3rd option of the browser asking for a resource that cannot be found, because it's the only one that would account for the situation you are seeing that server(get('/', ctx => ...)) does not work but server(ctx => ...) works.

from server.

AdamCollins avatar AdamCollins commented on June 3, 2024

The issue was option 3. After adding the references to the public folder the warning disappears.
Thank you!

from server.

franciscop avatar franciscop commented on June 3, 2024

Hey @AdamCollins, so I also went ahead and just published 1.0.19 fixing the issue on server.js side. Now the error message will be much more clear like this:

Your middleware did not return anything for this request:

GET /abc.png

This normally happens when no route was matched or if the router did not reply with anything. Make sure to return something, even if it's a catch-all error.

Documentation for reply: https://serverjs.io/documentation/reply/
Relevant issue: https://github.com/franciscop/server/issues/118

Please feel free to open any other issue you find 😄

from server.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.