Skip to content

Commit 95aa2bf

Browse files
authored
Base url with non empty path (#42)
1 parent 738c1a9 commit 95aa2bf

10 files changed

Lines changed: 94 additions & 37 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2929
- Change components so everything uses typescript
3030
- Add pinia store for external state management in loama
3131
- Add default image for logged in user
32+
- Apps can run in a non-empty base path ([issue #41](https://github.com/SolidLabResearch/loama/issues/41))

README.md

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,51 @@ relies on solid-common-lib.
4444

4545
## Getting started
4646

47-
### prerequisites
47+
### Prerequisites
4848

4949
- Node >= 20
5050
- Yarn >= 1.22.x
5151

52+
### Environment variables
53+
54+
The apps are configurable by means of some environment variables.
55+
56+
The environment variables are read from `.env[.mode]` files as [documented by Vite](https://v2.vitejs.dev/config/#environment-variables).
57+
58+
Each app has a file `.env.example` showing the possibilities.
59+
You may copy it to e.g. `.env` in the same directory and modify it to your needs.
60+
61+
One environment variable is common to all apps: `VITE_BASE`, allowing to run the app in a URL with a path.
62+
The loama `.env.example` file would result in the loama app running at e.g. `http://localhost:5173/loama/`.
63+
Very useful for running this app behind a reverse proxy!
64+
5265
### Development setup
5366

5467
We use yarn workspaces to manage our dependencies of all the subprojects.
5568

56-
Run `yarn` or `yarn install` to get all the dependencies
69+
Run `yarn` or `yarn install` to get all the dependencies.
70+
71+
Do this before starting loama a very first time after installation:
72+
73+
```bash
74+
# terminate all yarn dev commands below with <Ctrl-C> as soon as they display "Found 0 errors. Watching for file changes."
75+
cd ./solid-common-lib/
76+
yarn dev
77+
cd ../solid-app-lib/
78+
yarn dev
79+
cd ../controller/
80+
yarn dev
81+
```
82+
83+
To start the dev server for loama and its dependencies:
5784

58-
Finally we use [nx](nx.dev) to run a job in multiple projects. Simply start the dev servers for loama & its dependencies with:
85+
```bash
86+
yarn dev
87+
```
5988

60-
`yarn dev`
89+
This makes use of [nx](https://nx.dev) to run a job in multiple projects.
6190

62-
Now you can find loama at http://localhost:5173
91+
Now you can find loama at <http://localhost:5173>, or in a URL with a path, if you configured so in your `.env` as explained above.
6392

6493
### Using your own SOLID pod
6594

doctorapp/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VITE_BASE=/doctorapp/

doctorapp/vite.config.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
import { fileURLToPath, URL } from "node:url";
22

3-
import { defineConfig } from "vite";
3+
import { defineConfig, loadEnv } from "vite";
44
import vue from "@vitejs/plugin-vue";
55
import vueDevTools from "vite-plugin-vue-devtools";
66

77
// https://vitejs.dev/config/
8-
export default defineConfig({
9-
plugins: [vue(), vueDevTools()],
10-
resolve: {
11-
alias: {
12-
"@": fileURLToPath(new URL("./src", import.meta.url)),
13-
},
14-
},
15-
});
8+
export default defineConfig(({ mode }) => {
9+
const env = loadEnv(mode, process.cwd());
10+
const config = {
11+
plugins: [
12+
vue(),
13+
vueDevTools()
14+
],
15+
resolve: {
16+
alias: {
17+
'@': fileURLToPath(new URL('./src', import.meta.url))
18+
}
19+
},
20+
// available in app as import.meta.env.BASE_URL
21+
base: env.VITE_BASE
22+
}
23+
return config;
24+
})

loama/.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
VITE_DEFAULT_IDP=https://example.podprovider.com/
1+
VITE_BASE=/loama/
2+
VITE_DEFAULT_IDP=https://example.podprovider.com/

loama/vite.config.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
import { fileURLToPath, URL } from 'node:url'
22

3-
import { defineConfig } from 'vite'
3+
import { defineConfig, loadEnv } from 'vite'
44
import vue from '@vitejs/plugin-vue'
55
import vueDevTools from 'vite-plugin-vue-devtools'
66
import svgLoader from 'vite-svg-loader'
77

88
// https://vitejs.dev/config/
9-
export default defineConfig({
10-
plugins: [
11-
vue(),
12-
vueDevTools(),
13-
svgLoader()
14-
],
15-
resolve: {
16-
alias: {
17-
'@': fileURLToPath(new URL('./src', import.meta.url))
18-
}
9+
export default defineConfig(({ mode }) => {
10+
const env = loadEnv(mode, process.cwd());
11+
const config = {
12+
plugins: [
13+
vue(),
14+
vueDevTools(),
15+
svgLoader()
16+
],
17+
resolve: {
18+
alias: {
19+
'@': fileURLToPath(new URL('./src', import.meta.url))
20+
}
21+
},
22+
// available in app as import.meta.env.BASE_URL
23+
base: env.VITE_BASE || '/'
1924
}
25+
return config;
2026
})

mockbook/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VITE_BASE=/mockbook/

mockbook/vite.config.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
import { fileURLToPath, URL } from "node:url";
22

3-
import { defineConfig } from "vite";
3+
import { defineConfig, loadEnv } from "vite";
44
import vue from "@vitejs/plugin-vue";
55
import vueDevTools from "vite-plugin-vue-devtools";
66

77
// https://vitejs.dev/config/
8-
export default defineConfig({
9-
plugins: [vue(), vueDevTools()],
10-
resolve: {
11-
alias: {
12-
"@": fileURLToPath(new URL("./src", import.meta.url)),
13-
},
14-
},
15-
});
8+
export default defineConfig(({ mode }) => {
9+
const env = loadEnv(mode, process.cwd());
10+
const config = {
11+
plugins: [
12+
vue(),
13+
vueDevTools()
14+
],
15+
resolve: {
16+
alias: {
17+
'@': fileURLToPath(new URL('./src', import.meta.url))
18+
}
19+
},
20+
// available in app as import.meta.env.BASE_URL
21+
base: env.VITE_BASE
22+
}
23+
return config;
24+
})

solid-common-lib/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export async function getProfileInfo(
8181
const mbox = getUrl(profileThing, Schema.mbox) ?? "";
8282
const description =
8383
getStringWithLocale(profileThing, Schema.description, "en-us") ?? "";
84-
const img = getUrl(profileThing, Schema.img) ?? "/profile.svg";
84+
const img = getUrl(profileThing, Schema.img) ?? (import.meta.env.BASE_URL + "profile.svg");
8585
const phone = getUrl(profileThing, Schema.phone) ?? "";
8686

8787
return { name, mbox, description, img, phone };

solid-common-lib/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
3333
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
3434
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
35-
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
35+
"types": ["vite/client"], /* Specify type package names to be included without being referenced in a source file. */
3636
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
3737
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
3838
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */

0 commit comments

Comments
 (0)