node.js - Express: Index Route not called when index.html is served statically -


node v5 express 4.13.3

what did:

i serving out index.hmtl file when index route("/") hit. set public folder sent out static file.

what problem caused:

now static, index route no longer entered when browser opens index route e.g.(localhost:3000/)

question:

is expected behavior? idea serve index.html statically ?

is expected behavior?

yes. express pass request through list of middleware (including own index route), , if 1 of can handle request, , request finish (it won't passed other middleware).

the static middleware can handle request index (presumably because have index.html in public directory), request end there , not passed handler well.

the order in requests passed middleware can control. if want own index handler higher priority, should declare before static middleware:

app.get('/', function(req, res) {   ... });  app.use(express.static(...)); 

is idea serve index.html statically ?

if it's plain html , there's nothing else needs done when it's requested, it's best let static middleware handle it.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -