Skip to content

Commit

Permalink
fix(rest): Fix compilation error caused by @types/node
Browse files Browse the repository at this point in the history
@types/[email protected] introduces a breaking change for URL and our build
fails due to imcompatible types
  • Loading branch information
raymondfeng committed Dec 7, 2017
1 parent 0316f28 commit 89f1401
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@commitlint/config-angular": "^4.3.0",
"@commitlint/config-lerna-scopes": "^4.3.0",
"@types/mocha": "^2.2.44",
"@types/node": "^8.0.50",
"@types/node": "^8.0.56",
"@types/request": "^2.0.7",
"@types/request-promise": "^4.1.39",
"coveralls": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/rest/src/internal-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface ParsedRequest extends ServerRequest {
// see http://expressjs.com/en/4x/api.html#req.path
path: string;
// see http://expressjs.com/en/4x/api.html#req.query
query: {[key: string]: string};
query: {[key: string]: string | string[]};
// see https://github.com/DefinitelyTyped/DefinitelyTyped/issues/15808
url: string;
pathname: string;
Expand Down
8 changes: 7 additions & 1 deletion packages/rest/src/router/routing-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ export function parseRequestUrl(request: ServerRequest): ParsedRequest {
const parsedRequest = request as ParsedRequest;
const parsedUrl = url.parse(parsedRequest.url, true);
parsedRequest.path = parsedUrl.pathname || '/';
parsedRequest.query = parsedUrl.query;
// parsedUrl.query cannot be a string as it is parsed with
// parseQueryString = true
if (parsedUrl.query != null && typeof parsedUrl.query !== 'string') {
parsedRequest.query = parsedUrl.query;
} else {
parsedRequest.query = {};
}
return parsedRequest;
}

Expand Down

0 comments on commit 89f1401

Please sign in to comment.