Skip to content

Commit e6ed295

Browse files
committed
Fixes path_prefix flag
PR tensorflow#1512 introduced a bug where it formed a complete path without using existing pathname. Previously without forming the complete path, it was treated as a relative path from current window.location.pathname.
1 parent 762ab7d commit e6ed295

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

tensorboard/components/tf_backend/router.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ export interface Router {
2828
* Create a router for communicating with the TensorBoard backend. You
2929
* can pass this to `setRouter` to make it the global router.
3030
*
31-
* @param pathPrefix {string=} The base prefix for data endpoints.
31+
* @param pathPrefix {string} The base prefix for data endpoints.
3232
* @param demoMode {boolean=} Whether to modify urls for filesystem demo usage.
3333
*/
34-
export function createRouter(pathPrefix = 'data', demoMode = false): Router {
34+
export function createRouter(pathPrefix, demoMode = false): Router {
3535
if (pathPrefix[pathPrefix.length - 1] === '/') {
3636
pathPrefix = pathPrefix.slice(0, pathPrefix.length - 1);
3737
}
@@ -62,7 +62,13 @@ export function createRouter(pathPrefix = 'data', demoMode = false): Router {
6262
};
6363
};
6464

65-
let _router: Router = createRouter();
65+
export function getDefaultRouter(): Router {
66+
const sep = window.location.pathname.endsWith('/') ? '' : '/';
67+
const pathPrefix = window.location.pathname + sep + 'data';
68+
return createRouter(pathPrefix);
69+
}
70+
71+
let _router: Router = getDefaultRouter();
6672

6773
/**
6874
* @return {Router} the global router

tensorboard/components/tf_backend/test/backendTests.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,23 @@ describe('backend tests', () => {
8181
assert.equal(r.runs(), '/foo/runs');
8282
});
8383

84+
describe('default router', () => {
85+
beforeEach(function() {
86+
this.router = getDefaultRouter();
87+
});
88+
89+
it('makes sure test is not degenerate', function() {
90+
// Test becomes degenerate if location.pathname is empty.
91+
assert.notEqual('/', window.location.pathname);
92+
});
93+
94+
it('creates a URL including the pathname', function() {
95+
assert.equal(
96+
this.router.runs(),
97+
`${window.location.pathname}/data/runs`);
98+
});
99+
});
100+
84101
describe('prod mode', () => {
85102
beforeEach(function() {
86103
this.router = createRouter(base, /*demoMode=*/false);

0 commit comments

Comments
 (0)