Webapp handlers give blank page on localhost:3000

I have this simple code on my server js, and it seems to go through fine

Meteor.startup(() => {
WebApp.connectHandlers.use(async (req, res, next) => {
res.writeHead(200);
res.end();
});
});

But when I run via meteor run on localhost:3000, it simply shows a blank screen instead of my application (for reference, it normally shows my application just fine without the above mentioned code being in it)

Is this going to be an issue when I bundle it and deploy it on a site? I’m just planning on using it to receive some POST data from a link to the app itself.

You need to indicate a path as the first parameter of the handler

1 Like

As far as I based on the documentation, no I do not.

I’m using version 1.9 of meteor.

Just a heads up to anyone answering, I’m using Meteor version 1.9 and I do not intend to upgrade due to various potential dependencies going awry

“With the speed of tech, your debt is growing at fast pace.”

This post has been flagged by somebody as being spam “the community feels it is an advertisement, something that is overly promotional in nature instead of being useful or relevant to the topic as expected.”

I will rewrite this again as it was intened for @groudonzora . In general, it is best to keep systems up to date because the speed of tech is higher than it used to be years back. 2 years down the line and for some projects I might not even find the specific expertize in the market. Tech providers (hosts, oAuth, NPMs etc) might stop supporting old versions of various things. In this case “your debt is growing at fast pace.” - this is about technical debt or how far you are behind the to-date technology.

Meteor 1.9 webapp documentation: webapp | Meteor API Docs

WebApp.connectHandlers.use([path], handler) has two arguments:

Your app will be very inefficient if you do not indicate a path because:

  1. Your handler will be called on all routes to your app
  2. You need to add handling inside your callback to handle the specific path that you need to handle

Also, you need to call next() for those that will not meet #2 above so that your normal meteor code will be executed.

Too much handling than by simply specifying a path. Any reason why you are apprehensive about it?

1 Like

I appreciate the concern. The reason why is because I don’t have specific paths on my app. The app is at abc.com and there are no subdirectories on it.
I just use it to grab one piece of POST data, which is sent via a form from a part of a site that only a few people can access, (ie example.com/a-page-with-a-few-users).

From what I gathered, if my site is abc.com with no subdirectories, then if I put a path, such as “/path” then it would be called on abc.com/path which like I said doesn’t exist.

How would I use next() in this case to have it display my app after handling POST data? Would I need to do that just for testing on localhost:3000 or also on abc.com?

Just call next() at the end of your handler.

For what it is worth, you can use / as your path

1 Like

Path is not directory

Thank you.

Found an interesting issue though.

I tried calling next() and it gave me an error, though. Here’s the first part:

Error running template: Error [ERR_HTTP_HEADERS_SENT] [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:530:11)

The code I have now is this:

WebApp.connectHandlers.use("/", async (req, res, next) => {
res.writeHead(200);
res.end();
next();
});

Didn’t matter where I called next(), still had the issue. However, when I removed res.writeHead(200) and res.end() it worked!
Will I need to use them when I push deploy it to the live site and get the POST data coming to it? Again, I just need the body; it’s a single field I need to get.

No, you don’t need them

1 Like

I appreciate the help!
One last question, when I want to get the field in the POST data, is the format just req.body.fieldName?

Try POSTing and check the content of that variable.

For further reading, you can check this:

Thanks, I had to install body-parser middleware to read the body but I test-sent it a POST request and it was successful!