I have a router setup to accept any GET request that doesn't match the word "API" in it. This is for my single page app so that any bookmarked urls my javascript can't use its routes for.
The problem is every other time I refresh the page with a test url it fails.
URL: http://localhost:3000/my-test-url
First time hitting url, my index page loads.
Second time refreshing the page, error.
Cannot GET /my-test-url
Third time hitting refresh it works, and fourth time fails, and so on.
app.engine('html', cons.underscore);
app.set('view engine', 'html');
app.set('views', path.resolve(__dirname, '../client'));
// serve static content for the app from the "client" directory in the application directory
//express.static(path.join(__dirname, '../client')))
app.get(/^(?!.*\bapi\b).*$/ig, function(req, res) {
res.render('index');
});
app.listen(app.get('port'), function() {
console.log('Server up: http://localhost:' + app.get('port'));
});
Is there something that keeps the request open after it works the first time? The network tab in the browser shows the same URL each time but alternating with 404 error. Any suggestions are appreciated.
Aucun commentaire:
Enregistrer un commentaire