Skip to content

Commit

Permalink
fix(bazel): http server should support loading jsonp files
Browse files Browse the repository at this point in the history
An actual file may be resolved, but with URL params. The params
should be omitted when we resolve a file from the runfiles.
  • Loading branch information
devversion committed Dec 14, 2022
1 parent f1e8862 commit 4d9ea67
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion bazel/http-server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ export class HttpServer {
) {
res.end(this._getIndexHtmlContent());
} else {
const resolvedPath = this._resolveUrlFromRunfiles(req.url);
const pathname = this._getPathnameFromRequestURL(req.url);
const resolvedPath = this._resolveUrlFromRunfiles(pathname);

if (resolvedPath === null) {
res.statusCode = 404;
Expand All @@ -113,6 +114,14 @@ export class HttpServer {
}
}

/**
* Gets the pathname from a given request URL.
* e.g. `/some_file.json?jsonp=bla` -> `/some_file.json`.
*/
private _getPathnameFromRequestURL(reqURL: string) {
return new URL(reqURL, `http://_`).pathname;
}

/** Resolves a given URL from the runfiles using the corresponding manifest path. */
private _resolveUrlFromRunfiles(url: string): string | null {
for (let rootPath of this._rootPaths) {
Expand Down

0 comments on commit 4d9ea67

Please sign in to comment.