Skip to content

Commit 971a5ea

Browse files
replace proxy
1 parent f241e5c commit 971a5ea

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

vite.config.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { resolve } from 'path'
1616
const extraPlugins: PluginOption[] = [];
1717

1818
const GITHUB_RUNTIME_PERMANENT_NAME = process.env.GITHUB_RUNTIME_PERMANENT_NAME || process.env.CODESPACE_NAME?.substring(0, 20);
19+
const GITHUB_API_URL = process.env.GITHUB_API_URL || "https://api.github.com";
1920
const projectRoot = process.env.PROJECT_ROOT || import.meta.dirname
2021

2122
// https://vite.dev/config/
@@ -68,21 +69,23 @@ export default defineConfig({
6869
"./src/styles/theme.css",
6970
],
7071
},
71-
proxy: {
72-
// Any new endpoints defined in the backend server need to be added here
73-
// as vite serves the frontend during local development and in the live preview,
74-
// and needs to know to proxy the endpoints to the backend server.
75-
"/_spark/kv": {
76-
target: "http://localhost:8000",
77-
changeOrigin: true,
78-
},
79-
"/_spark/llm": {
80-
target: "http://localhost:8000",
81-
changeOrigin: true,
82-
},
83-
"/_spark/user": {
84-
target: "http://localhost:8000",
72+
proxy: {
73+
"/_spark/**": {
74+
target: GITHUB_API_URL,
8575
changeOrigin: true,
76+
rewrite: (path) => {
77+
// Extract the service name (kv, llm, user) from the path
78+
const serviceName = path.replace("/_spark/", "").split("/")[0];
79+
return path.replace(`/_spark/${serviceName}`, `/runtime/${GITHUB_RUNTIME_PERMANENT_NAME}/${serviceName}`);
80+
},
81+
configure: (proxy, options) => {
82+
proxy.on('proxyReq', (proxyReq, req, res) => {
83+
// Add GitHub token authentication
84+
if (process.env.GITHUB_TOKEN) {
85+
proxyReq.setHeader('Authorization', `token ${process.env.GITHUB_TOKEN}`);
86+
}
87+
});
88+
},
8689
},
8790
},
8891
},

0 commit comments

Comments
 (0)