Flaska: If http server supports listenAsync (service-core for example) then use that instead of callback listen()
continuous-integration/appveyor/branch AppVeyor build succeeded Details

master v1.2.1
Jonatan Nilsson 2022-03-27 14:48:11 +00:00
parent b97e34c1eb
commit 975646d336
3 changed files with 53 additions and 2 deletions

View File

@ -1066,6 +1066,10 @@ ctx.state.nonce = nonce;
this.compile()
this.server = this.http.createServer(this.requestStart.bind(this))
if (this.server.listenAsync && typeof(this.server.listenAsync) === 'function') {
return this.server.listenAsync(port, ip)
}
return new Promise((res, rej) => {
this.server.listen(port, ip, function(err) {
if (err) return rej(err)

View File

@ -1,6 +1,6 @@
{
"name": "flaska",
"version": "1.2.0",
"version": "1.2.1",
"description": "Flaska is a micro web-framework for node. It is designed to be fast, simple and lightweight, and is distributed as a single file module with no dependencies.",
"main": "flaska.mjs",
"scripts": {

View File

@ -925,7 +925,7 @@ t.describe('#listenAsync()', function() {
assert.strictEqual(checkIp, assertIp)
})
t.test('call http correctly if only port specified', async function() {
t.test('call http and listen correctly if only port specified', async function() {
const assertPort = 325897235
let checkPort = null
let checkIp = null
@ -945,6 +945,53 @@ t.describe('#listenAsync()', function() {
assert.strictEqual(checkPort, assertPort)
assert.strictEqual(checkIp, '::')
})
t.test('call http and listenAsync correctly if supported', async function() {
const assertPort = 4632
const assertIp = 'asdf'
const assertReturns = { a: 1 }
const stubListenAsync = stub().resolves(assertReturns)
let flaska = new Flaska({}, {
createServer: function() {
return {
listenAsync: stubListenAsync,
}
}
})
assert.ok(flaska.requestStart)
flaska.requestStart = function() {
checkInternalThis = this
checkIsTrue = true
}
let res = await flaska.listenAsync(assertPort, assertIp)
assert.strictEqual(res, assertReturns)
assert.strictEqual(stubListenAsync.firstCall[0], assertPort)
assert.strictEqual(stubListenAsync.firstCall[1], assertIp)
})
t.test('call http and listenAsync correctly if supported and ip is null', async function() {
const assertPort = 325897235
const assertReturns = { a: 1 }
const stubListenAsync = stub().resolves(assertReturns)
let flaska = new Flaska({}, {
createServer: function() {
return {
listenAsync: stubListenAsync,
}
}
})
assert.ok(flaska.requestStart)
flaska.requestStart = function() {
checkInternalThis = this
checkIsTrue = true
}
let res = await flaska.listenAsync(assertPort)
assert.strictEqual(res, assertReturns)
assert.strictEqual(stubListenAsync.firstCall[0], assertPort)
assert.strictEqual(stubListenAsync.firstCall[1], '::')
})
t.test('register requestStart if no async', async function() {
let checkIsTrue = false