@curveball/core
Advanced tools
Comparing version 0.14.2 to 0.14.3
Changelog | ||
========= | ||
0.14.3 (2020-09-23) | ||
------------------- | ||
* #155 - `listen` and `listenWs` now both have a second `host` argument to | ||
bind to a specific interface. (@Nicholaiii) | ||
* #145 - `request.headers` and `response.headers` now have a `getMany()` | ||
function to get a list of header values for a given header name. (@Nicholaiii) | ||
0.14.2 (2020-07-14) | ||
@@ -5,0 +14,0 @@ ------------------- |
@@ -44,4 +44,4 @@ /// <reference types="node" /> | ||
*/ | ||
listen(port: number): http.Server; | ||
listenWs(port: number): WebSocket.Server; | ||
listen(port: number, host?: string): http.Server; | ||
listenWs(port: number, host?: string): WebSocket.Server; | ||
/** | ||
@@ -48,0 +48,0 @@ * This function is a callback that can be used for Node's http.Server, |
@@ -73,10 +73,11 @@ "use strict"; | ||
*/ | ||
listen(port) { | ||
listen(port, host) { | ||
const server = http_1.default.createServer(this.callback()); | ||
server.on('upgrade', this.upgradeCallback.bind(this)); | ||
return server.listen(port); | ||
return server.listen(port, host); | ||
} | ||
listenWs(port) { | ||
listenWs(port, host) { | ||
const wss = new ws_1.default.Server({ | ||
port | ||
port, | ||
host | ||
}); | ||
@@ -83,0 +84,0 @@ wss.on('connection', async (ws, req) => { |
@@ -20,2 +20,9 @@ /** | ||
/** | ||
* Gets all values of a HTTP header | ||
* | ||
* This function will return an array with 0 or more values of a header. | ||
* | ||
*/ | ||
getMany(name: string): string[]; | ||
/** | ||
* Returns true or false depending on if a HTTP header exists. | ||
@@ -65,2 +72,9 @@ */ | ||
/** | ||
* Gets all values of a HTTP header | ||
* | ||
* This function will return an array with 0 or more values of a header. | ||
* | ||
*/ | ||
getMany(name: string): string[]; | ||
/** | ||
* Returns true or false depending on if a HTTP header exists. | ||
@@ -67,0 +81,0 @@ */ |
@@ -45,2 +45,21 @@ "use strict"; | ||
/** | ||
* Gets all values of a HTTP header | ||
* | ||
* This function will return an array with 0 or more values of a header. | ||
* | ||
*/ | ||
getMany(name) { | ||
const tuple = this.store[name.toLowerCase()]; | ||
if (tuple === undefined) { | ||
return []; | ||
} | ||
const value = tuple[1]; | ||
if (Array.isArray(value)) { | ||
return value; | ||
} | ||
else { | ||
return [value.toString()]; | ||
} | ||
} | ||
/** | ||
* Returns true or false depending on if a HTTP header exists. | ||
@@ -47,0 +66,0 @@ */ |
@@ -17,3 +17,3 @@ "use strict"; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -20,0 +20,0 @@ return result; |
@@ -25,2 +25,9 @@ import { HeadersInterface, HeadersObject } from '../headers'; | ||
/** | ||
* Gets all values of a HTTP header | ||
* | ||
* This function will return an array with 0 or more values of a header. | ||
* | ||
*/ | ||
getMany(name: string): string[]; | ||
/** | ||
* Returns true or false depending on if a HTTP header exists. | ||
@@ -27,0 +34,0 @@ */ |
@@ -42,2 +42,20 @@ "use strict"; | ||
/** | ||
* Gets all values of a HTTP header | ||
* | ||
* This function will return an array with 0 or more values of a header. | ||
* | ||
*/ | ||
getMany(name) { | ||
const value = this.inner.getHeader(name); | ||
if (value === undefined || value === null) { | ||
return []; | ||
} | ||
else if (Array.isArray(value)) { | ||
return value; | ||
} | ||
else { | ||
return [value.toString()]; | ||
} | ||
} | ||
/** | ||
* Returns true or false depending on if a HTTP header exists. | ||
@@ -44,0 +62,0 @@ */ |
@@ -8,3 +8,3 @@ import { Middleware } from '../application'; | ||
private inner; | ||
private bodyValue?; | ||
private bodyValue; | ||
private explicitStatus; | ||
@@ -27,7 +27,7 @@ constructor(inner: NodeHttpResponse); | ||
*/ | ||
set body(value: T | undefined); | ||
set body(value: T); | ||
/** | ||
* Returns the response body. | ||
*/ | ||
get body(): T | undefined; | ||
get body(): T; | ||
/** | ||
@@ -34,0 +34,0 @@ * Sends an informational response before the real response. |
@@ -21,3 +21,3 @@ "use strict"; | ||
this.inner = inner; | ||
// @ts-expect-error: Typescript doesn't like null here because it might be | ||
// @ts-expect-error Typescript doesn't like null here because it might be | ||
// incompatible with T, but we're ignoring it as it's a good default. | ||
@@ -24,0 +24,0 @@ this.body = null; |
@@ -19,3 +19,3 @@ import { Middleware } from './application'; | ||
*/ | ||
body: any; | ||
body: T; | ||
/** | ||
@@ -22,0 +22,0 @@ * Returns the value of the Content-Type header, with any additional |
{ | ||
"name": "@curveball/core", | ||
"version": "0.14.2", | ||
"version": "0.14.3", | ||
"description": "Curveball is a framework writting in Typescript for Node.js", | ||
@@ -37,18 +37,18 @@ "main": "dist/index.js", | ||
"@types/accepts": "^1.3.5", | ||
"@types/chai": "^4.2.11", | ||
"@types/chai": "^4.2.12", | ||
"@types/co-body": "^5.1.0", | ||
"@types/mocha": "^8.0.0", | ||
"@types/node": "^10.17.27", | ||
"@types/mocha": "^8.0.3", | ||
"@types/node": "^10.17.35", | ||
"@types/node-fetch": "^2.5.7", | ||
"@types/sinon": "^9.0.4", | ||
"@typescript-eslint/eslint-plugin": "^3.6.1", | ||
"@typescript-eslint/parser": "^3.6.1", | ||
"@types/sinon": "^9.0.5", | ||
"@typescript-eslint/eslint-plugin": "^4.2.0", | ||
"@typescript-eslint/parser": "^4.2.0", | ||
"chai": "^4.2.0", | ||
"eslint": "^7.4.0", | ||
"mocha": "^8.0.1", | ||
"node-fetch": "^2.6.0", | ||
"eslint": "^7.9.0", | ||
"mocha": "^8.1.3", | ||
"node-fetch": "^2.6.1", | ||
"nyc": "^15.1.0", | ||
"sinon": "^9.0.2", | ||
"ts-node": "^8.10.2", | ||
"typescript": "^3.9.6" | ||
"sinon": "^9.0.3", | ||
"ts-node": "^9.0.0", | ||
"typescript": "^4.0.3" | ||
}, | ||
@@ -55,0 +55,0 @@ "types": "dist/", |
@@ -103,12 +103,13 @@ import { isHttpError } from '@curveball/http-errors'; | ||
*/ | ||
listen(port: number): http.Server { | ||
listen(port: number, host?: string): http.Server { | ||
const server = http.createServer(this.callback()); | ||
server.on('upgrade', this.upgradeCallback.bind(this)); | ||
return server.listen(port); | ||
return server.listen(port, host); | ||
} | ||
listenWs(port: number): WebSocket.Server { | ||
listenWs(port: number, host?: string): WebSocket.Server { | ||
const wss = new WebSocket.Server({ | ||
port | ||
port, | ||
host | ||
}); | ||
@@ -115,0 +116,0 @@ wss.on('connection', async(ws, req) => { |
@@ -23,2 +23,10 @@ /** | ||
/** | ||
* Gets all values of a HTTP header | ||
* | ||
* This function will return an array with 0 or more values of a header. | ||
* | ||
*/ | ||
getMany(name: string): string[]; | ||
/** | ||
* Returns true or false depending on if a HTTP header exists. | ||
@@ -109,2 +117,23 @@ */ | ||
/** | ||
* Gets all values of a HTTP header | ||
* | ||
* This function will return an array with 0 or more values of a header. | ||
* | ||
*/ | ||
getMany(name: string): string[] { | ||
const tuple = this.store[name.toLowerCase()]; | ||
if (tuple === undefined) { | ||
return []; | ||
} | ||
const value = tuple[1]; | ||
if (Array.isArray(value)) { | ||
return value; | ||
} else { | ||
return [value.toString()]; | ||
} | ||
} | ||
/** | ||
* Returns true or false depending on if a HTTP header exists. | ||
@@ -111,0 +140,0 @@ */ |
@@ -11,3 +11,3 @@ import { Headers } from './headers'; | ||
this.status = 200; | ||
this.body = null; | ||
(this.body as any) = null; | ||
@@ -14,0 +14,0 @@ } |
@@ -52,2 +52,20 @@ import { HeadersInterface, HeadersObject } from '../headers'; | ||
/** | ||
* Gets all values of a HTTP header | ||
* | ||
* This function will return an array with 0 or more values of a header. | ||
* | ||
*/ | ||
getMany(name: string): string[] { | ||
const value = this.inner.getHeader(name); | ||
if (value === undefined || value === null) { | ||
return []; | ||
} else if (Array.isArray(value)) { | ||
return value; | ||
} else { | ||
return [value.toString()]; | ||
} | ||
} | ||
/** | ||
* Returns true or false depending on if a HTTP header exists. | ||
@@ -54,0 +72,0 @@ */ |
@@ -17,3 +17,3 @@ import http from 'http'; | ||
private inner: NodeHttpResponse; | ||
private bodyValue?: T; | ||
private bodyValue!: T; | ||
private explicitStatus: boolean; | ||
@@ -26,3 +26,3 @@ | ||
// @ts-expect-error: Typescript doesn't like null here because it might be | ||
// @ts-expect-error Typescript doesn't like null here because it might be | ||
// incompatible with T, but we're ignoring it as it's a good default. | ||
@@ -66,3 +66,3 @@ this.body = null; | ||
*/ | ||
set body(value: T | undefined) { | ||
set body(value: T) { | ||
@@ -79,3 +79,3 @@ if (!this.explicitStatus) { | ||
*/ | ||
get body(): T | undefined { | ||
get body(): T { | ||
@@ -82,0 +82,0 @@ return this.bodyValue; |
@@ -31,3 +31,3 @@ import { Middleware } from './application'; | ||
*/ | ||
body: any; | ||
body!: T; | ||
@@ -34,0 +34,0 @@ /** |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
190233
79
4369