Skip to content
This repository has been archived by the owner on Apr 30, 2019. It is now read-only.

Commit

Permalink
app.server.httpServer renamed to app.server.http
Browse files Browse the repository at this point in the history
  • Loading branch information
akyoto committed Mar 23, 2016
1 parent f67d96a commit f3016a5
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 20 deletions.
15 changes: 15 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ app.rewrite((request, response) => {
})
```

## Accessing HTTP server

You can retrieve the http server object using:

```js
app.server.http
```

## Accessing all routes

```js
Object.keys(app.server.routes) // ['GET', 'POST']
Object.keys(app.server.routes.GET) // ['', 'blog', 'contact']
```

## Express compatibility

Aero aims to be as Express compatible as possible, however 100% API compatibility is not the goal.
10 changes: 5 additions & 5 deletions lib/LiveReload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ let UglifyJS = require('uglify-js')
class LiveReload {
constructor(app) {
if(app.security && app.security.key && app.security.cert) {
this.httpServer = require('spdy').createServer(app.security, () => null)
this.http = require('spdy').createServer(app.security, () => null)
this.protocol = 'wss'
} else {
this.httpServer = require('http').createServer(() => null)
this.http = require('http').createServer(() => null)
this.protocol = 'ws'
}

Expand All @@ -23,12 +23,12 @@ class LiveReload {
}).code.replace('${protocol}', this.protocol).replace('${port}', app.config.ports.liveReload)

// Listen
this.httpServer.listen(app.config.ports.liveReload, error => {
this.http.listen(app.config.ports.liveReload, error => {
if(error)
throw error

this.server = new WebSocket.Server({
server: this.httpServer
server: this.http
})
})
}
Expand Down Expand Up @@ -62,7 +62,7 @@ class LiveReload {
if(!this.server)
return Promise.resolve()

let closeAsync = Promise.promisify(this.httpServer.close, {context: this.httpServer})
let closeAsync = Promise.promisify(this.http.close, {context: this.http})
let closeWebSocketAsync = Promise.promisify(this.server.close, {context: this.server})

return closeWebSocketAsync().then(() => closeAsync())
Expand Down
11 changes: 6 additions & 5 deletions lib/Server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ class Server {
POST: new Set()
}

this.modifiers = []
this.rewrite = null
this.http = null
this.protocol = ''
this.port = null
this.modifiers = [] // Middleware
this.rewrite = null // Pre-routing
this.http = null // Node server object
this.lib = null // Node server module
this.protocol = '' // Protocol used (http or https)
this.port = null // Port
}
}

Expand Down
12 changes: 6 additions & 6 deletions lib/Server/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ let run = function(config, security) {

Object.assign(options, security)

this.http = require('spdy')
this.httpServer = this.http.createServer(options, this.onRequest.bind(this))
this.lib = require('spdy')
this.http = this.lib.createServer(options, this.onRequest.bind(this))

// Set up a permanent redirection to HTTPS
this.redirectServer = require('http').createServer((request, response) => {
Expand All @@ -40,13 +40,13 @@ let run = function(config, security) {
} else {
this.protocol = 'http'
this.port = config.ports.http
this.http = require('http')
this.httpServer = this.http.createServer(this.onRequest.bind(this))
this.lib = require('http')
this.http = this.lib.createServer(this.onRequest.bind(this))
}

this.trackConnections(this.httpServer, this)
this.trackConnections(this.http, this)

let listen = Promise.promisify(this.httpServer.listen, {context: this.httpServer})
let listen = Promise.promisify(this.http.listen, {context: this.http})
return listen(this.port, '::')
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Server/stop.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = Promise.coroutine(function*() {
if(!this.httpServer)
if(!this.http)
return

let closeHTTPServer = Promise.promisify(this.httpServer.close, {context: this.httpServer})
this.httpServer.closeSockets()
let closeHTTPServer = Promise.promisify(this.http.close, {context: this.http})
this.http.closeSockets()
yield closeHTTPServer()

if(!this.redirectServer)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aero",
"version": "1.4.1",
"version": "1.4.2",
"description": "The fastest web framework on the node platform.",
"repository": "aerojs/aero",
"homepage": "https://github.com/aerojs/aero",
Expand Down

0 comments on commit f3016a5

Please sign in to comment.