node.js - Node js Express Framework - regex not working -
i trying use reg ex express route in node app. want route match path '/' or '/index.html' instead matches :(
here's route.
app.get(/\/(index.html)?/, function(req, res){ res.set('content-type', 'text/plain'); res.send('hello node!'); });
how can regular expression work?
try this:
app.get(/^\/(index\.html)?$/, function(req, res){ res.set('content-type', 'text/plain'); res.send('hello node!'); });
without $
, following first /
can still match, , index.html
optional prefix. without ^
, match /something/index.html
.
Comments
Post a Comment