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

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -