Skip to content

Commit 66ec99b

Browse files
authored
Serving from a base URL including a non-empty path (#166)
1 parent 9219c14 commit 66ec99b

File tree

14 files changed

+30
-12
lines changed

14 files changed

+30
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ lintPush.sh
2929

3030
test/cypress/screenshots
3131
test/cypress/downloads
32+
test/serve-this

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Works when served from any base URL including a path (e.g. `https://www.example.com/your/preferred/path`) (#165).
13+
1014
## [1.4.0] - 2024-10-02
1115

1216
### Added

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ npm run build
9999

100100
The static build appears in directory `main/dist`.
101101

102+
This static build can be served on a webserver without modifications from the host's root path (e.g. `https://www.example.com`), or from any other path (e.g. `https://www.example.com/your/preferred/path`).
103+
102104
## Logging in
103105

104106
Some queries access data sources that are only readable by authenticated users. This requires you to log in.
@@ -359,6 +361,8 @@ For testing with the provided configuration file, we use [Cypress](https://www.c
359361
360362
The development version might be tested repeatedly during development.
361363

364+
Both the production version and the development version are tested from a non-empty path in the base URL.
365+
362366
### Testing the production version
363367

364368
1. Build the production version of the Web application and serve it:
@@ -400,10 +404,10 @@ The development version might be tested repeatedly during development.
400404

401405
The procedure is the same as for testing the production version, except for step 1, which is now:
402406

403-
1. Start the Web application in development mode:
407+
1. Start the Web application in development mode, using a non-empty path in the base URL:
404408

405409
In directory `main`:
406410

407411
```bash
408-
npm run dev
412+
npm run dev-with-path
409413
```

main/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"lint:fix": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0 --fix",
1111
"lint:markdown": "markdownlint-cli2",
1212
"lint:markdown:fix": "markdownlint-cli2-fix",
13-
"preview": "vite preview"
13+
"preview": "vite preview",
14+
"dev-with-path": "vite --base /random/path"
1415
},
1516
"dependencies": {
1617
"@comunica/query-sparql": "^3.2.3",

main/src/authenticationProvider/authenticationProvider.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export default {
3434
try {
3535
await session.login({
3636
oidcIssuer: idp,
37-
redirectUrl: new URL("/", window.location.href).toString(),
37+
// leading dot needed to run from any path
38+
redirectUrl: new URL('.', window.location.href).toString(),
3839
clientName: "Generic Data Viewer",
3940
});
4041
} catch (error) {

main/vite.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ export default defineConfig({
99
// necessary for crypto lib to work
1010
global: 'globalThis'
1111
},
12+
// leading dot needed to run from any path
13+
base: './'
1214
})

test/cypress.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default defineConfig({
55
experimentalStudio: true,
66
experimentalRunAllSpecs: true,
77
defaultCommandTimeout: 10000, /* is OK for very slow computers */
8-
baseUrl: 'http://localhost:5173',
8+
baseUrl: 'http://localhost:5173/random/path',
99
video: false
1010
},
1111
});

test/cypress/e2e/fetch-status.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe("Fetch Status", () => {
4949
cy.contains("button", "Authorize").click();
5050
});
5151

52-
cy.url().should("eq", "http://localhost:5173/");
52+
cy.url().should("eq", Cypress.config('baseUrl') + "/");
5353

5454
// Go to the mixed book query
5555
cy.contains("For testing only").click();

test/cypress/e2e/log-in.cy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe("Log in", () => {
4848
cy.contains("button", "Authorize").click();
4949
});
5050

51-
cy.url().should("eq", "http://localhost:5173/");
51+
cy.url().should("eq", Cypress.config('baseUrl') + "/");
5252
});
5353

5454
it("Log in with an invalid IDP issuer", () => {
@@ -83,7 +83,7 @@ describe("Log in", () => {
8383
cy.contains("button", "Authorize").click();
8484
});
8585

86-
cy.url().should("eq", "http://localhost:5173/");
86+
cy.url().should("eq", Cypress.config('baseUrl') + "/");
8787

8888
cy.contains("General examples").click();
8989
cy.contains("A secret list of my favorite books").click();

test/cypress/e2e/save-custom-queries-on-pod.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe("Saving custom queries on pods - logged in", () => {
3131
cy.contains("button", "Authorize").click();
3232
});
3333

34-
cy.url().should("eq", "http://localhost:5173/");
34+
cy.url().should("eq", Cypress.config('baseUrl') + "/");
3535

3636
cy.visit("/#");
3737
});

0 commit comments

Comments
 (0)