mirror of https://github.com/lukechilds/got.git
Vsevolod Strukchinsky
9 years ago
15 changed files with 294 additions and 267 deletions
@ -1,39 +1,41 @@ |
|||||
import http from 'http'; |
import http from 'http'; |
||||
import https from 'https'; |
import https from 'https'; |
||||
import pify from 'pify'; |
import pify from 'pify'; |
||||
|
import getPort from 'get-port'; |
||||
|
|
||||
export const host = 'localhost'; |
export const host = 'localhost'; |
||||
export let port = 6767; |
const getPortify = pify(getPort); |
||||
export let portSSL = 16167; |
|
||||
|
|
||||
export const createServer = port2 => { |
export const createServer = () => { |
||||
port = port2 || ++port; |
return getPortify() |
||||
|
.then(port => { |
||||
|
const s = http.createServer((req, resp) => s.emit(req.url, req, resp)); |
||||
|
|
||||
const s = http.createServer((req, resp) => s.emit(req.url, req, resp)); |
s.host = host; |
||||
|
s.port = port; |
||||
|
s.url = `http://${host}:${port}`; |
||||
|
s.protocol = 'http'; |
||||
|
|
||||
s.host = host; |
s.listen = pify(s.listen); |
||||
s.port = port; |
s.close = pify(s.close); |
||||
s.url = `http://${host}:${port}`; |
|
||||
s.protocol = 'http'; |
|
||||
|
|
||||
s.listen = pify(s.listen); |
return s; |
||||
s.close = pify(s.close); |
}); |
||||
|
|
||||
return s; |
|
||||
}; |
}; |
||||
|
|
||||
export const createSSLServer = (portSSL2, opts) => { |
export const createSSLServer = (opts) => { |
||||
portSSL = portSSL2 || ++portSSL; |
return getPortify() |
||||
|
.then(port => { |
||||
const s = https.createServer(opts, (req, resp) => s.emit(req.url, req, resp)); |
const s = https.createServer(opts, (req, resp) => s.emit(req.url, req, resp)); |
||||
|
|
||||
s.host = host; |
s.host = host; |
||||
s.port = portSSL; |
s.port = port; |
||||
s.url = `https://${host}:${portSSL}`; |
s.url = `https://${host}:${port}`; |
||||
s.protocol = 'https'; |
s.protocol = 'https'; |
||||
|
|
||||
s.listen = pify(s.listen); |
s.listen = pify(s.listen); |
||||
s.close = pify(s.close); |
s.close = pify(s.close); |
||||
|
|
||||
return s; |
return s; |
||||
|
}); |
||||
}; |
}; |
||||
|
Loading…
Reference in new issue