M
M
Maxim Grudin2016-10-15 16:31:37
JavaScript
Maxim Grudin, 2016-10-15 16:31:37

How to solve routing problem in express nodejs server?

Server.js has the following routes:

app.get("/users/:username/obj.json", objController.index);
app.get("/users/:username", UsersController.show);

There is a route on the client side $.getJSON("obj.json", function (objects)...
When site.com/users/user is navigated to, index.html is displayed with user-specific elements. But the page loads without these elements with a GET site.com/users/obj.json 404 (Not Found) error in the browser. The server does not give any error.
Why does a specific user disappear in the route to match obj.json and how to fix it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maa-Kut, 2016-10-17
@GMax

See RFC1808 . The relative URL is relative to the base URL of the page. According to section 3.3 of the referenced document, for the site.com/users/johndoe page, the base URL will be site.com/users. The relative URL becomes site.com/users/obj.json accordingly.
The first thing that comes to mind is to change the user page URL format to something like: site.com/users/johndoe/show. <base>You can also try playing with the tag .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question