I am building a Node.js application that has many .html files. Rather than having to go and specify a routing for each and every one of them, is there a way for the routing to be done automatically?
Ideally this would happen:
Request received for "/Test.html". It then checks a given folder for a file called "Test.html". I can optionally override this automatic wiring.
I recommend using Express.js and it's static middleware:
app.configure(function(){
...
var oneYear = 31557600000;
app.use(express.static(__dirname + '/public', { maxAge: oneYear }));
});
If a request to /test.html is made, then the static middleware looks into the "public" folder and checks if the file exists (if it exists it serves it).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With