Skip to content

Commit d0c6883

Browse files
committed
added a config
1 parent ec208d5 commit d0c6883

10 files changed

Lines changed: 82 additions & 62 deletions

File tree

.github/workflows/build-and-deploy-dev.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
name: Build and Deploy to Dev
22

33
on:
4-
workflow_dispatch:
54
push:
65
branches:
76
- main
8-
- yektay/rpm_module
97

108
permissions:
119
contents: write
@@ -27,7 +25,7 @@ jobs:
2725
run: echo "image_tag=dev-${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
2826

2927
- name: Setup pnpm
30-
uses: ad-build-test/action-setup@v4
28+
uses: pnpm/action-setup@v4
3129
with:
3230
run_install: false
3331

@@ -39,7 +37,7 @@ jobs:
3937
- run: pnpm install
4038

4139
- name: Install Rust stable
42-
uses: ad-build-test/rust-toolchain@stable
40+
uses: dtolnay/rust-toolchain@stable
4341
with:
4442
toolchain: 1.93.1
4543

@@ -63,14 +61,13 @@ jobs:
6361
6462
- name: Build Tauri package
6563
id: build
66-
uses: ad-build-test/tauri-action@v0.6.1
64+
uses: tauri-apps/tauri-action@v0.6.1
6765
env:
6866
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
69-
VITE_API_URL: http://lcls-dev9:8080
7067
with:
7168
args: >-
7269
--bundles rpm
73-
--config {"tauri":{"bundle":{"identifier":"edu.stanford.slac.squirrel"}}}
70+
--config {"tauri":{"bundle":{"identifier":"edu.stanford.slac.squirrel"},"allowlist":{"fs":{"readFile":true,"scope":["$RESOURCE/*"]},"path":{"all":true}}}}
7471
7572
- name: Find RPM file
7673
id: find-rpm
@@ -82,7 +79,7 @@ jobs:
8279
echo "Found RPM: $RPM_NAME"
8380
8481
- name: Create/update dev-latest pre-release
85-
uses: ad-build-test/action-gh-release@v2
82+
uses: softprops/action-gh-release@v2
8683
with:
8784
tag_name: dev-latest
8885
name: Dev Latest
@@ -95,7 +92,7 @@ jobs:
9592
9693
deploy:
9794
needs: build
98-
uses: ad-build-test/build-system-playbooks/.github/workflows/request-deployment.yml@yektay/rpm_module
95+
uses: ad-build-test/build-system-playbooks/.github/workflows/request-deployment.yml@main
9996
with:
10097
deploy_to_dev: true
10198
tag: ${{ needs.build.outputs.image_tag }}

.github/workflows/build-release.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
uses: actions/checkout@v4
1616

1717
- name: Setup pnpm
18-
uses: ad-build-test/action-setup@v4
18+
uses: pnpm/action-setup@v4
1919
with:
2020
run_install: false
2121

@@ -27,7 +27,7 @@ jobs:
2727
- run: pnpm install
2828

2929
- name: Install Rust stable
30-
uses: ad-build-test/rust-toolchain@stable
30+
uses: dtolnay/rust-toolchain@stable
3131
with:
3232
toolchain: 1.93.1
3333

@@ -51,16 +51,15 @@ jobs:
5151
5252
- name: Build Tauri package
5353
id: build
54-
uses: ad-build-test/tauri-action@v0.6.1
54+
uses: tauri-apps/tauri-action@v0.6.1
5555
env:
5656
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57-
VITE_API_URL: http://lcls-dev9:8080
5857
with:
5958
args: >-
6059
--bundles rpm
61-
--config {"tauri":{"bundle":{"identifier":"edu.stanford.slac.squirrel"}}}
60+
--config {"tauri":{"bundle":{"identifier":"edu.stanford.slac.squirrel"},"allowlist":{"fs":{"readFile":true,"scope":["$RESOURCE/*"]},"path":{"all":true}}}}
6261
6362
- name: Attach RPM to release
64-
uses: ad-build-test/action-gh-release@v2
63+
uses: softprops/action-gh-release@v2
6564
with:
6665
files: src-tauri/target/release/bundle/rpm/*.rpm

.github/workflows/deploy-prod.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
5050
deploy:
5151
needs: find-rpm
52-
uses: ad-build-test/build-system-playbooks/.github/workflows/request-deployment.yml@yektay/rpm_module
52+
uses: ad-build-test/build-system-playbooks/.github/workflows/request-deployment.yml@main
5353
with:
5454
deploy_to_lcls: ${{ inputs.deploy_to_lcls }}
5555
deploy_to_facet: ${{ inputs.deploy_to_facet }}

config.json.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"apiUrl": "http://localhost:8080"
3+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@tanstack/react-virtual": "^3.13.13",
1515
"react": "^18.2.0",
1616
"react-dom": "^18.2.0",
17+
"@tauri-apps/api": "^1.6.0",
1718
"socket.io-client": "^4.8.1"
1819
},
1920
"devDependencies": {

pnpm-lock.yaml

Lines changed: 9 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config/api.ts

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,41 @@
11
/**
2-
* API configuration for score-backend
3-
* Based on configuration from superscore/squirrel-local.cfg
2+
* API configuration for squirrel-backend
43
*
54
* In dev mode, Vite proxy forwards /v1/* to http://localhost:8080.
6-
* In production (Tauri), VITE_API_URL is set at build time per facility.
5+
* In production (Tauri), config.json is read at startup to determine the backend URL.
6+
* Falls back to VITE_API_URL env var if config.json is not available.
77
*/
88

9+
let runtimeBaseURL: string | null = null;
10+
11+
/**
12+
* Load runtime configuration from config.json via Tauri FS API.
13+
* Must be called before the app renders. No-ops in non-Tauri environments.
14+
*/
15+
export async function loadRuntimeConfig(): Promise<void> {
16+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, no-underscore-dangle
17+
if (!(window as any).__TAURI__) return;
18+
19+
try {
20+
const { resolveResource } = await import('@tauri-apps/api/path');
21+
const { readTextFile } = await import('@tauri-apps/api/fs');
22+
23+
const configPath = await resolveResource('config.json');
24+
const text = await readTextFile(configPath);
25+
const config = JSON.parse(text);
26+
if (config.apiUrl) {
27+
runtimeBaseURL = config.apiUrl;
28+
}
29+
} catch (e) {
30+
// eslint-disable-next-line no-console
31+
console.warn('Could not load config.json, using build-time fallback');
32+
}
33+
}
34+
935
export const API_CONFIG = {
10-
baseURL: import.meta.env.VITE_API_URL || '',
36+
get baseURL(): string {
37+
return runtimeBaseURL || import.meta.env.VITE_API_URL || '';
38+
},
1139
endpoints: {
1240
snapshots: '/v1/snapshots',
1341
pvs: '/v1/pvs',
@@ -18,7 +46,7 @@ export const API_CONFIG = {
1846
};
1947

2048
/**
21-
* Generic API response wrapper from score-backend
49+
* Generic API response wrapper from squirrel-backend
2250
*/
2351
export interface ApiResultResponse<T> {
2452
errorCode: number;

src/main.tsx

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { HeartbeatProvider } from './contexts/HeartbeatContext';
66
import { LivePVProvider } from './contexts/LivePVContext';
77
import { SnapshotProvider } from './contexts/SnapshotContext';
88
import { AdminModeProvider } from './contexts/AdminModeContext';
9+
import { loadRuntimeConfig } from './config/api';
910

1011
// Import the generated route tree
1112
import { routeTree } from './routeTree.gen';
@@ -32,18 +33,21 @@ declare module '@tanstack/react-router' {
3233
}
3334
}
3435

35-
ReactDOM.createRoot(document.getElementById('root')!).render(
36-
<React.StrictMode>
37-
<QueryClientProvider client={queryClient}>
38-
<AdminModeProvider>
39-
<HeartbeatProvider pollIntervalMs={2000}>
40-
<LivePVProvider pollInterval={2000}>
41-
<SnapshotProvider>
42-
<RouterProvider router={router} />
43-
</SnapshotProvider>
44-
</LivePVProvider>
45-
</HeartbeatProvider>
46-
</AdminModeProvider>
47-
</QueryClientProvider>
48-
</React.StrictMode>
49-
);
36+
// Load runtime config (reads config.json in Tauri, no-ops in dev) then render
37+
loadRuntimeConfig().then(() => {
38+
ReactDOM.createRoot(document.getElementById('root')!).render(
39+
<React.StrictMode>
40+
<QueryClientProvider client={queryClient}>
41+
<AdminModeProvider>
42+
<HeartbeatProvider pollIntervalMs={2000}>
43+
<LivePVProvider pollInterval={2000}>
44+
<SnapshotProvider>
45+
<RouterProvider router={router} />
46+
</SnapshotProvider>
47+
</LivePVProvider>
48+
</HeartbeatProvider>
49+
</AdminModeProvider>
50+
</QueryClientProvider>
51+
</React.StrictMode>
52+
);
53+
});

src/services/apiClient.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
11
/**
2-
* Base API client for making HTTP requests to score-backend
2+
* Base API client for making HTTP requests to squirrel-backend
33
*/
44

55
import { API_CONFIG, ApiResultResponse } from '../config/api';
66

77
class APIClient {
8-
private baseURL: string;
9-
10-
private timeout: number;
11-
12-
constructor() {
13-
this.baseURL = API_CONFIG.baseURL;
14-
this.timeout = API_CONFIG.timeout;
15-
}
16-
8+
// eslint-disable-next-line class-methods-use-this
179
private async request<T>(endpoint: string, options: RequestInit = {}): Promise<T> {
18-
const url = `${this.baseURL}${endpoint}`;
10+
const url = `${API_CONFIG.baseURL}${endpoint}`;
1911

2012
const controller = new AbortController();
21-
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
13+
const timeoutId = setTimeout(() => controller.abort(), API_CONFIG.timeout);
2214

2315
try {
2416
const response = await fetch(url, {

src/types/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* API type definitions matching score-backend DTOs
2+
* API type definitions matching squirrel-backend DTOs
33
*/
44

55
/**

0 commit comments

Comments
 (0)