-
Notifications
You must be signed in to change notification settings - Fork 20
How to serve static files outside of aero on root route '/'? #81
Comments
Something like express.static is available if you specify a directory, e.g. There is no sendFile function on the response object yet as I've only written Jade in my projects so far, never HTML directly. You can however add a page with a controller (.js) that sends a file manually and route it to |
"You can however add a page with a controller (.js) that sends a file manually"
|
I know it's annoying because sendFile() doesn't exist yet but something like this does work: let serveJSFile = fileName => {
return (request, response) => {
let filePath = path.join(__dirname, fileName)
let stat = fs.statSync(filePath)
response.writeHead(200, {
'Content-Type': 'application/javascript',
'Content-Length': stat.size
})
fs.createReadStream(filePath).pipe(response)
}
}
app.get('service-worker.js', serveJSFile('worker/service-worker.js'))
app.get('cache-polyfill.js', serveJSFile('worker/cache-polyfill.js')) Note that this is just an example and it's not async. You can however easily create async controllers by promisify'ing the |
I implemented sendFile() in |
Hey, thanks for taking the time to make this project.
I want to serve my index.html from a separate client project when I hit '/'. Is there something like express.static? Is the a method like sendFile for the response object?
Thank you!
The text was updated successfully, but these errors were encountered: