let aero = require('aero')
let app = aero()
app.get('/hello', (request, response) => {
response.end('Hello!')
})
app.get(/^\+(.*)$/, (request, response) => {
response.end(request.params[0])
})
app.use(function(request, response, next) {
console.log(request.url)
next()
})
app.use(function*(request, response, next) {
let start = new Date
yield next()
let ms = new Date - start
console.log(request.url, ms + ' ms')
})
Not supported yet.
app.use(
session(options),
passport.initialize(),
passport.session()
)
app.run()
returns app.ready
which is a promise that gets resolved when the server loaded all pages and started the server.
app.run().then(() => {
console.log('We are online!')
})
app.ready.then(() => {
console.log('We are online!')
})
app.redirect('/index.html', '/')
app.rewrite((request, response) => {
// Handle /+MyName requests as /user/MyName internally
if(request.url.startsWith('/+')) {
request.url = '/user/' + request.url.substring('/+'.length)
return
}
// Also rewrite ajax routes for the aero-ajax plugin
if(request.url.startsWith('/_/+')) {
request.url = '/_/user/' + request.url.substring('/_/+'.length)
return
}
})
app.rewrite((request, response) => {
if(request.headers.host.indexOf('old-domain.com') !== -1) {
response.redirect('https://new-domain.com' + request.url)
// By returning true we stop the call chain.
// Therefore routing will not happen.
return true
}
})
app.root
You can retrieve the http server object using:
app.server.http
Object.keys(app.server.routes) // ['GET', 'POST']
Object.keys(app.server.routes.GET) // ['', 'blog', 'contact']
response.json({
example: 'JSON data'
})
response.redirect('https://google.com')
response.sendFile('data.txt')
response.statusCode = 404
Aero aims to be as Express compatible as possible, however 100% API compatibility is not the goal.