Note that there are some explanatory texts on larger screens.

plurals
  1. PONode.js/Express Routing to a static file URL
    primarykey
    data
    text
    <p>I don't have a problem as such as I have a work-around. However the process of understanding and developing the work-around has highlighted what seems to me a fundamental gap in my knowledge (as a self-taught programmer, this happens a lot ;-) !) and I can't seem to find the answer to plug it anywhere.</p> <p>Standard node.js/express setup with for example:</p> <pre><code>app.get('/index.htm', function (request, response) { console.log("/index.htm"); }); app.get('*', function (request, response) { console.log("*"); }); </code></pre> <p>Why when the user connects directly to index.htm (by typing in the URL although I've not tried clicking on a link) does nothing fire ? The page is served no problem. The obvious use-case for this is to check if the user is authenticated prior to serving the static page.</p> <p>FYI the workaround is to pass the user to a route such as "/authenticated" (which matches fine), do the check and then redirect and basically block everything else.</p> <p>Thanks for educating me in advance ;-)</p> <p>N</p> <p>UPDATE to Raynos' question - yes (ignore the server/app variable name discrepancy).</p> <pre><code>// CREATE SERVER var server = express.createServer(); server.configure(function() { server.use(express.static(__dirname + '/public')); server.use(express.logger()); server.use(express.errorHandler({dumpExceptions: true, showStack: true})); // start of session stuff server.use(express.cookieParser()); server.use(express.session({store: sessionStore, secret: 'secret', key: 'express.sid'})); }); </code></pre> <p>I've now found that the routing matches fine once you delete the static file i.e. in the original example, deleting index.htm means that the console will now log "/index.htm". </p> <p>N</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload