Comparing version 1.2.0 to 1.2.1
@@ -21,3 +21,3 @@ const uWS = require('uWebSockets.js') | ||
const reqWrapper = new HttpRequest(req) | ||
const resWrapper = new HttpResponse(res) | ||
const resWrapper = new HttpResponse(res, server) | ||
@@ -52,2 +52,17 @@ const method = reqWrapper.method | ||
server.start = (port, cb) => { | ||
server.listen(port, socket => { | ||
server._socket = socket | ||
cb(socket) | ||
}) | ||
} | ||
server._date = new Date().toUTCString() | ||
const timer = setInterval(() => (server._date = new Date().toUTCString()), 1000) | ||
server.close = () => { | ||
clearInterval(timer) | ||
uWS.us_listen_socket_close(server._socket) | ||
} | ||
return server | ||
@@ -81,4 +96,5 @@ } | ||
class HttpResponse { | ||
constructor (res) { | ||
constructor (res, server) { | ||
this.res = res | ||
this.server = server | ||
@@ -114,2 +130,3 @@ this.statusCode = 200 | ||
this.res.writeStatus(`${this.statusCode} ${this.statusMessage}`) | ||
this.res.writeHeader('Date', this.server._date) | ||
@@ -116,0 +133,0 @@ Object.keys(this.headers).forEach(name => { |
{ | ||
"name": "0http", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Cero friction HTTP request router. The need for speed!", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
/* global describe, it */ | ||
const expect = require('chai').expect | ||
const request = require('supertest') | ||
const uWS = require('uWebSockets.js') | ||
@@ -9,3 +8,2 @@ describe('0http Web Framework - Smoke', () => { | ||
let socket | ||
const { router, server } = require('./index')({ | ||
@@ -43,5 +41,4 @@ server: require('./lib/server/low')(), | ||
server.listen(~~process.env.PORT, serverSocket => { | ||
server.start(~~process.env.PORT, serverSocket => { | ||
if (serverSocket) { | ||
socket = serverSocket | ||
done() | ||
@@ -108,4 +105,4 @@ } | ||
it('should successfully terminate the service', async () => { | ||
uWS.us_listen_socket_close(socket) | ||
server.close() | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
16191
374
1