@curveball/core
Advanced tools
Comparing version
Changelog | ||
========= | ||
0.17.0 (2022-02-08) | ||
------------------- | ||
* `listen()` now starts a WebSocket service on the same port by default. | ||
* `listenWs()` is now deprecated, and will be removed in a future version. | ||
* JSON is now pretty-printed by default. | ||
Happy birthday Mom! | ||
0.16.4 (2022-01-05) | ||
@@ -5,0 +14,0 @@ ------------------- |
@@ -45,2 +45,10 @@ /// <reference types="node" /> | ||
listen(port: number, host?: string): http.Server; | ||
/** | ||
* Starts a Websocket-only server on the specified port. | ||
* | ||
* Note that this is now deprecated. The listen() function already starts | ||
* a websocket on the main HTTP port, so this is somewhat redundant. | ||
* | ||
* @deprecated | ||
*/ | ||
listenWs(port: number, host?: string): WebSocket.Server; | ||
@@ -47,0 +55,0 @@ /** |
@@ -75,2 +75,10 @@ "use strict"; | ||
} | ||
/** | ||
* Starts a Websocket-only server on the specified port. | ||
* | ||
* Note that this is now deprecated. The listen() function already starts | ||
* a websocket on the main HTTP port, so this is somewhat redundant. | ||
* | ||
* @deprecated | ||
*/ | ||
listenWs(port, host) { | ||
@@ -128,2 +136,9 @@ const wss = new WebSocket.Server({ | ||
this.wss = new WebSocket.Server({ noServer: true }); | ||
this.wss.on('connection', async (ws, req) => { | ||
const request = new request_1.default(req); | ||
const response = new memory_response_1.default(); | ||
const context = new base_context_1.default(request, response); | ||
context.webSocket = ws; | ||
await this.handle(context); | ||
}); | ||
} | ||
@@ -130,0 +145,0 @@ this.wss.handleUpgrade(request, socket, head, (ws) => { |
@@ -42,3 +42,3 @@ "use strict"; | ||
// Memoizing the JSON object case. | ||
this.originalBody = JSON.stringify(this.originalBody); | ||
this.originalBody = JSON.stringify(this.originalBody, null, 2); | ||
} | ||
@@ -45,0 +45,0 @@ if (this.originalBody instanceof Buffer) { |
@@ -27,3 +27,3 @@ "use strict"; | ||
else if (typeof body === 'object') { | ||
res.end(JSON.stringify(body)); | ||
res.end(JSON.stringify(body, null, 2)); | ||
} | ||
@@ -30,0 +30,0 @@ else if (typeof body === 'function') { |
{ | ||
"name": "@curveball/core", | ||
"version": "0.16.4", | ||
"version": "0.17.0", | ||
"description": "Curveball is a framework writting in Typescript for Node.js", | ||
@@ -50,3 +50,3 @@ "main": "dist/index.js", | ||
"nyc": "^15.1.0", | ||
"sinon": "^12.0.1", | ||
"sinon": "^13.0.1", | ||
"ts-node": "^10.4.0", | ||
@@ -66,3 +66,3 @@ "typescript": "^4.1.5" | ||
"raw-body": "^2.4.1", | ||
"ws": "^7.5.6" | ||
"ws": "^7.5.7" | ||
}, | ||
@@ -69,0 +69,0 @@ "engines": { |
@@ -106,5 +106,14 @@ import { isHttpError } from '@curveball/http-errors'; | ||
server.on('upgrade', this.upgradeCallback.bind(this)); | ||
return server.listen(port, host); | ||
} | ||
/** | ||
* Starts a Websocket-only server on the specified port. | ||
* | ||
* Note that this is now deprecated. The listen() function already starts | ||
* a websocket on the main HTTP port, so this is somewhat redundant. | ||
* | ||
* @deprecated | ||
*/ | ||
listenWs(port: number, host?: string): WebSocket.Server { | ||
@@ -175,2 +184,10 @@ | ||
this.wss = new WebSocket.Server({ noServer: true }); | ||
this.wss.on('connection', async(ws, req) => { | ||
const request = new NodeRequest(req); | ||
const response = new MemoryResponse(); | ||
const context = new BaseContext(request, response); | ||
context.webSocket = ws; | ||
await this.handle(context); | ||
}); | ||
} | ||
@@ -177,0 +194,0 @@ this.wss.handleUpgrade(request, socket, head, (ws: WebSocket) => { |
@@ -44,3 +44,3 @@ import { Middleware } from './application'; | ||
*/ | ||
method: string; | ||
method: string; | ||
@@ -47,0 +47,0 @@ /** |
@@ -83,3 +83,3 @@ import { Readable } from 'stream'; | ||
// Memoizing the JSON object case. | ||
this.originalBody = JSON.stringify(this.originalBody); | ||
this.originalBody = JSON.stringify(this.originalBody, null, 2); | ||
} | ||
@@ -86,0 +86,0 @@ |
@@ -37,3 +37,3 @@ import * as http from 'http'; | ||
} else if (typeof body === 'object') { | ||
res.end(JSON.stringify(body)); | ||
res.end(JSON.stringify(body, null , 2)); | ||
} else if (typeof body === 'function') { | ||
@@ -40,0 +40,0 @@ body(res as Writable); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
175450
1.21%3976
0.96%Updated