Package Exports
- http-server-plus
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (http-server-plus) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
http-server-plus
Augmented
http.Server, HTTP/HTTPS/HTTP2 and multiple ports on the same instance
Install
Download manually or with package-manager.
npm
npm install --save http-server-plusTo add support for HTTP/2:
npm install --save spdyExample
// The `create()` method can also take a `requestListener`, just like
// `http.createServer()`.
var app = require('express')()
var server = require('http-server-plus').create(app)
// The listen method returns a promise which resolves when the server
// starts listening.
require('bluebird').all([
// Listen on port localhost:80.
server.listen({
hostname: 'localhost',
port: 80
}),
// Listen on port 443, using HTTPS.
server.listen({
port: 443,
cert: require('fs').readFileSync(__dirname +'/certificate.pem'),
key: require('fs').readFileSync(__dirname +'/private_key.pem')
}),
// Listen on socket.
server.listen({
socket: __dirname +'/http.sock'
}),
// Listen on file descriptor (with systemd for instance).
server.listen({
fd: 3
})
]).then(function (niceAddresses) {
console.log('server is listening on', niceAddresses)
}).catch(function (error) {
console.error('The server could not listen on', error.niceAddress)
})Using ES2016's async functions:
import createExpressApp from 'express'
import {create} from 'http-server-plus'
async function main () {
const app = createExpressApp()
// The `create()` method can also take a `requestListener`, just
// like `http.createServer()`.
const server = create(app)
try {
// The listen method returns a promise which resolves when the server
// starts listening.
const niceAddresses = await Promise.all([
// Listen on port localhost:80.
server.listen({
hostname: 'localhost',
port: 80
}),
// Listen on port 443, using HTTPS.
server.listen({
port: 443,
cert: require('fs').readFileSync(__dirname +'/certificate.pem'),
key: require('fs').readFileSync(__dirname +'/private_key.pem')
}),
// Listen on socket.
server.listen({
socket: __dirname +'/http.sock'
})
])
console.log('the server is listening on', niceAdresses)
} catch (error) {
console.error('the server could not listen on', error.niceAddress)
}
}Contributing
Contributions are very welcome, either on the documentation or on the code.
You may:
- report any issue you've encountered;
- fork and create a pull request.
License
ISC © Julien Fontanet