Send A Static File For A Specifed URL
I am currently using parse to deploy my web app. I am using Express to route the url to the appropriate content. Currently I trying to serve index.html for the following url; myst
Solution 1:
You could have a wrong path. To look at errors try this:
res.sendFile('index.html', function (err) {
if (err) {
console.log(err);
}
else {
console.log('File sent!');
}
});
Solution 2:
From http://expressjs.com/4x/api.html#res.sendFile:
Unless the root option is set in the options object, path must be an absolute path of the file.
Update 1: I tried this:
app.get('/test', function(req,res) {
try {
res.sendFile('test.html');
} catch (err) {
res.send('ERROR ' + err);
}
});
It produces:
ERROR TypeError: Object [object Object] has no method 'sendFile'
I then stumbled across this: How to manually serve files on Parse.com?. The relevant quote:
...it seems Parse runs a custom subset of Node modules. They've erased all filesystem methods. There's no sendFile() on Express API, no readFile() on fs module...
Update 2:
Parse sets up a static file handler for your app, so try this:
app.get('/hi', function(req, res){
res.redirect('/index.html');
});
Post a Comment for "Send A Static File For A Specifed URL"