@curveball/core
Advanced tools
Comparing version 0.9.4 to 0.10.0
Changelog | ||
========= | ||
0.10.0 (2020-01-05) | ||
------------------- | ||
* Added a `redirect()` function to `Context` and `Response` objects, making it | ||
easier to set a status-code and location header in one step. | ||
* Support for more `Prefer` parameters: `depth-noroot`, `safe`, `transclude`. | ||
0.9.4 (2019-12-21) | ||
@@ -5,0 +13,0 @@ ------------------ |
@@ -103,2 +103,4 @@ import { Middleware } from './application'; | ||
ip(trustProxy?: boolean): null | string; | ||
redirect(address: string): void; | ||
redirect(status: number, address: string): void; | ||
} |
@@ -104,4 +104,26 @@ "use strict"; | ||
} | ||
/** | ||
* redirect redirects the response with an optionally provided HTTP status | ||
* code in the first position to the location provided in address. If no status | ||
* is provided, 303 See Other is used. | ||
* | ||
* It is a wrapper method for the underlying Response.redirect function. | ||
* | ||
* @param {(string|number)} addrOrStatus if passed a string, the string will | ||
* be used to set the Location header of the response object and the default status | ||
* of 303 See Other will be used. If a number, an addressed must be passed in the second | ||
* argument. | ||
* @param {string} address If addrOrStatus is passed a status code, this value is | ||
* set as the value of the response's Location header. | ||
*/ | ||
redirect(addrOrStatus, address = '') { | ||
if (typeof (addrOrStatus) === 'number') { | ||
return this.response.redirect(addrOrStatus, address); | ||
} | ||
else { | ||
return this.response.redirect(addrOrStatus); | ||
} | ||
} | ||
} | ||
exports.default = Context; | ||
//# sourceMappingURL=context.js.map |
@@ -130,8 +130,14 @@ /// <reference types="node" /> | ||
* if there was no value. | ||
* | ||
* The list of supported preferences is taken from the IANA registry: | ||
* https://www.iana.org/assignments/http-parameters/http-parameters.xhtml#preferences | ||
* | ||
* In addition to this list, it also supports the 'transclude' draft: | ||
* https://github.com/inadarei/draft-prefer-transclude/blob/master/draft.md | ||
*/ | ||
prefer(preference: 'respond-async'): boolean; | ||
prefer(preference: 'depth-noroot' | 'respond-async' | 'safe' | 'wait'): boolean; | ||
prefer(preference: 'return'): 'representation' | 'minimal' | false; | ||
prefer(preference: 'wait'): string | false; | ||
prefer(preference: 'handling'): 'strict' | 'lenient' | false; | ||
prefer(preference: 'transclude'): string | false; | ||
} | ||
export default Request; |
@@ -58,3 +58,5 @@ import { Middleware } from './application'; | ||
is(type: string): boolean; | ||
redirect(address: string): void; | ||
redirect(status: number, address: string): void; | ||
} | ||
export default Response; |
@@ -61,2 +61,27 @@ "use strict"; | ||
} | ||
/** | ||
* redirect redirects the response with an optionally provided HTTP status | ||
* code in the first position to the location provided in address. If no status | ||
* is provided, 303 See Other is used. | ||
* | ||
* @param {(string|number)} addrOrStatus if passed a string, the string will | ||
* be used to set the Location header of the response object and the default status | ||
* of 303 See Other will be used. If a number, an addressed must be passed in the second | ||
* argument. | ||
* @param {string} address If addrOrStatus is passed a status code, this value is | ||
* set as the value of the response's Location header. | ||
*/ | ||
redirect(addrOrStatus, address = '') { | ||
let status = 303; | ||
let addr; | ||
if (typeof (addrOrStatus) === 'number') { | ||
status = addrOrStatus; | ||
addr = address; | ||
} | ||
else { | ||
addr = addrOrStatus; | ||
} | ||
this.status = status; | ||
this.headers.set('Location', addr); | ||
} | ||
} | ||
@@ -63,0 +88,0 @@ exports.Response = Response; |
{ | ||
"name": "@curveball/core", | ||
"version": "0.9.4", | ||
"version": "0.10.0", | ||
"description": "Curveball is a framework writting in Typescript for Node.js", | ||
@@ -45,4 +45,4 @@ "main": "dist/index.js", | ||
"node-fetch": "^2.6.0", | ||
"nyc": "^14.1.1", | ||
"sinon": "^7.5.0", | ||
"nyc": "^15.0.0", | ||
"sinon": "^8.0.0", | ||
"ts-node": "^8.5.4", | ||
@@ -49,0 +49,0 @@ "tslint": "^5.20.1", |
@@ -235,2 +235,4 @@ Curveball | ||
* `push(callback: Middleware)` - Do a HTTP/2 push. | ||
* `redirect(status, location)` - Send a redirect status code and set a | ||
`Location` header. | ||
@@ -279,2 +281,4 @@ | ||
`hal+json` and `json`. | ||
* `redirect(status, location)` - Send a redirect status code and set a | ||
`Location` header. | ||
@@ -281,0 +285,0 @@ ### The Headers interface |
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
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
100975
1887
306