Home > Mobile >  What path should I use for Meteor's Webapp API?
What path should I use for Meteor's Webapp API?

Time:01-10

I'm using Meteor v1.9 Webapp API to have my app listen to HTTP requests, specifically from a link to the app itself from a website, let's say example.org.

The documentation says to use

WebApp.connectHandlers.use([path], handler)

Where the [path] is defined as such:

path - an optional path field. This handler will only be called on paths that match this string. The match has to border on a / or a .. For example, /hello will match /hello/world and /hello.world, but not /hello_world.

My question: Let's say my meteor application is hosted on abc.com and the POST data being sent over to it is from example.org (where the link to abc.com is as well). For the [path] argument mentioned above, in this case, should I have it as "/example" since example.org is where my app is listening to requests from (getting the POST data)? Or does it have to be a different format? I tried the former, but it doesn't seem to be working for it, so I'm trying to find the root of the issue.

Additional information that might be useful: I know it says 'optional' so I tried omitting it, but when I tested it out via 'meteor run' where it runs off of localhost:3000, it just yielded a blank page, with no errors and a success sent back, probably because it uses a GET request instead of POST. My code for the webapp in my meteor application is as follows:

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

Also technically my meteor application is built/bundled and deployed as a Node.js application on the website, but that shouldn't affect anything regarding this as far as I could tell.

CodePudding user response:

That path is the path (part of the URL) on your meteor server. So in your example, for instance,

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

means that you will need to send your POST requests to abc.com/example.

  •  Tags:  
  • Related