Comments (4)
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 fs
module and calling yield fs.statAsync(filePath)
instead of fs.statSync
.
from aero.
I implemented sendFile() in app
and response
in version 1.4.4, see #83 for usage information.
from aero.
Something like express.static is available if you specify a directory, e.g. images
, inside the static
array of your config.json
file. Then the files inside images
will be served under /images
.
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 /
via the url
property in your .json file.
from aero.
"You can however add a page with a controller (.js) that sends a file manually"
- Send the file manually by setting the response headers and reading from the file system using fs?
from aero.
Related Issues (20)
- Can we set Body Parser and Serializer? HOT 1
- Unable to bind to dynamic ports (Heroku) HOT 2
- Automatically changing the page title HOT 3
- Proper way to use socket.io with aero? HOT 4
- Implement response.sendFile() and app.sendFile()
- How to use app variable in pages ? HOT 4
- Unknown plugin error in aero-ajax HOT 4
- Cache HTML 5 validator results HOT 1
- Server stop error HOT 1
- Add a watcher for api-keys.json
- If-None-Match HOT 1
- Configurable max-age
- markdown-it HOT 1
- uWebSockets HOT 1
- How to use route parameters ? HOT 2
- Global mixins (for pug templates)
- From 99/100 back to 100/100 PageSpeed
- GPL -> LGPL/ZLIB/BSD/MIT? HOT 6
- Road map HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aero.