Z
Z
Zheka Dzecina2016-10-19 15:30:37
JavaScript
Zheka Dzecina, 2016-10-19 15:30:37

Setting up express + angular 2 routes?

Hello! I'm doing a project in Angular 2 + express. I can not properly configure routes on the server. The main page loads well; I turn to the internal, too, everything is fine. But when I reload the page, I get only data (json) without a front-end , this is how the route
setting
app.use(express.static(__dirname + '/../')); //getting the frontend, so the path is index.html
app.get('/place/info/1', function(req, res) {
res.json({
id: "df",
name: "name"
} );
});
what needs to be done to get the index for any routes and at the same time get your own json?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
_
_ _, 2016-10-19
@Zhe1ka

Make a middleware that will always render index for the Accept: text/html header,
and give API data for Accept: application/json

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question