fix: correct route registration - use full paths in rjweb-server path.http() calls

rjweb-server path.http() second argument is the FULL path, not relative to prefix.
Changed all routes from server.path('/prefix', path => path.http(method, '/suffix', ...))
to server.path('/', path => path.http(method, '/prefix/suffix', ...)).

Also fixed:
- Duplicate createContext import in useAuth.ts
- notFound handler now excludes /webhook paths from SPA fallback

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-07-25 00:28:14 +02:00
parent 1fd41420c7
commit 8da5d6eef3
2 changed files with 38 additions and 39 deletions
+37 -37
View File
@@ -44,44 +44,44 @@ export const server = new Server(
); );
// Auth // Auth
server.path("/api/auth", (path) => path server.path("/", (path) => path
.http("POST", "/login", (http) => http.onRequest(loginHandler)) .http("POST", "/api/auth/login", (http) => http.onRequest(loginHandler))
.http("POST", "/logout", (http) => http.onRequest(logoutHandler)) .http("POST", "/api/auth/logout", (http) => http.onRequest(logoutHandler))
.http("GET", "/me", (http) => http.onRequest(meHandler)) .http("GET", "/api/auth/me", (http) => http.onRequest(meHandler))
.http("GET", "/setup-status", (http) => http.onRequest(setupStatusHandler)) .http("GET", "/api/auth/setup-status", (http) => http.onRequest(setupStatusHandler))
.http("POST", "/first-user", (http) => http.onRequest(firstUserHandler)) .http("POST", "/api/auth/first-user", (http) => http.onRequest(firstUserHandler))
); );
// Webhook // Webhook
server.path("/webhook", (path) => path server.path("/", (path) => path
.http("POST", "/:userId", (http) => http.onRequest(webhookHandler)) .http("POST", "/webhook/:userId", (http) => http.onRequest(webhookHandler))
); );
// User settings // User settings
server.path("/api/user", (path) => path server.path("/", (path) => path
.http("GET", "/settings", (http) => http.onRequest(getUserSettings)) .http("GET", "/api/user/settings", (http) => http.onRequest(getUserSettings))
.http("PATCH", "/username", (http) => http.onRequest(updateUsername)) .http("PATCH", "/api/user/username", (http) => http.onRequest(updateUsername))
.http("PATCH", "/password", (http) => http.onRequest(updatePassword)) .http("PATCH", "/api/user/password", (http) => http.onRequest(updatePassword))
.http("PUT", "/gitea", (http) => http.onRequest(updateGitea)) .http("PUT", "/api/user/gitea", (http) => http.onRequest(updateGitea))
.http("PUT", "/aws", (http) => http.onRequest(updateAws)) .http("PUT", "/api/user/aws", (http) => http.onRequest(updateAws))
.http("GET", "/webhook-secret", (http) => http.onRequest(getWebhookSecret)) .http("GET", "/api/user/webhook-secret", (http) => http.onRequest(getWebhookSecret))
.http("POST", "/webhook-secret/regenerate", (http) => http.onRequest(regenerateWebhookSecret)) .http("POST", "/api/user/webhook-secret/regenerate", (http) => http.onRequest(regenerateWebhookSecret))
); );
// Repos // Repos
server.path("/api/repos", (path) => path server.path("/", (path) => path
.http("GET", "/", (http) => http.onRequest(listRepos)) .http("GET", "/api/repos", (http) => http.onRequest(listRepos))
.http("POST", "/config", (http) => http.onRequest(saveRepoConfig)) .http("POST", "/api/repos/config", (http) => http.onRequest(saveRepoConfig))
.http("POST", "/toggle", (http) => http.onRequest(toggleRepoEnabled)) .http("POST", "/api/repos/toggle", (http) => http.onRequest(toggleRepoEnabled))
.http("GET", "/:owner/:repo/config", (http) => http.onRequest(getRepoConfig)) .http("GET", "/api/repos/:owner/:repo/config", (http) => http.onRequest(getRepoConfig))
); );
// Previews // Previews
server.path("/api/previews", (path) => path server.path("/", (path) => path
.http("GET", "/", (http) => http.onRequest(listPreviews)) .http("GET", "/api/previews", (http) => http.onRequest(listPreviews))
.http("GET", "/:id", (http) => http.onRequest(getPreview)) .http("GET", "/api/previews/:id", (http) => http.onRequest(getPreview))
.http("POST", "/:id/stop", (http) => http.onRequest(stopPreviewRoute)) .http("POST", "/api/previews/:id/stop", (http) => http.onRequest(stopPreviewRoute))
.ws("/:id/logs", (ws) => ws .ws("/api/previews/:id/logs", (ws) => ws
.onOpen(previewLogsWs) .onOpen(previewLogsWs)
.onMessage(async () => {}) .onMessage(async () => {})
.onClose(async () => {}) .onClose(async () => {})
@@ -89,25 +89,25 @@ server.path("/api/previews", (path) => path
); );
// Admin // Admin
server.path("/api/admin", (path) => path server.path("/", (path) => path
.http("GET", "/users", (http) => http.onRequest(listUsers)) .http("GET", "/api/admin/users", (http) => http.onRequest(listUsers))
.http("POST", "/users", (http) => http.onRequest(createUser)) .http("POST", "/api/admin/users", (http) => http.onRequest(createUser))
.http("PATCH", "/users/:id", (http) => http.onRequest(updateUser)) .http("PATCH", "/api/admin/users/:id", (http) => http.onRequest(updateUser))
.http("DELETE", "/users/:id", (http) => http.onRequest(deleteUser)) .http("DELETE", "/api/admin/users/:id", (http) => http.onRequest(deleteUser))
.http("GET", "/settings", (http) => http.onRequest(getSettings)) .http("GET", "/api/admin/settings", (http) => http.onRequest(getSettings))
.http("PUT", "/settings", (http) => http.onRequest(updateSettings)) .http("PUT", "/api/admin/settings", (http) => http.onRequest(updateSettings))
.http("GET", "/previews", (http) => http.onRequest(adminListPreviews)) .http("GET", "/api/admin/previews", (http) => http.onRequest(adminListPreviews))
.http("POST", "/previews/:id/stop", (http) => http.onRequest(adminStopPreview)) .http("POST", "/api/admin/previews/:id/stop", (http) => http.onRequest(adminStopPreview))
); );
// Static UI // Static UI — must come AFTER API routes
if (hasUiBuild) { if (hasUiBuild) {
server.path("/", (path) => path.static(uiBuildPath)); server.path("/", (path) => path.static(uiBuildPath));
} }
server.notFound(async (ctr) => { server.notFound(async (ctr) => {
const STATIC_EXT = /\.(js|mjs|css|png|jpg|jpeg|gif|svg|ico|woff2?|ttf|eot|map|json|txt|xml|webp|avif)(\?.*)?$/i; const STATIC_EXT = /\.(js|mjs|css|png|jpg|jpeg|gif|svg|ico|woff2?|ttf|eot|map|json|txt|xml|webp|avif)(\?.*)?$/i;
if (!ctr.url.path.startsWith("/api") && !STATIC_EXT.test(ctr.url.path) && existsSync(uiIndexPath)) { if (!ctr.url.path.startsWith("/api") && !ctr.url.path.startsWith("/webhook") && !STATIC_EXT.test(ctr.url.path) && existsSync(uiIndexPath)) {
return ctr.status(200).printFile(uiIndexPath, { addTypes: true }); return ctr.status(200).printFile(uiIndexPath, { addTypes: true });
} }
return makeResponse({ ctr, content: { code: ERROR_MESSAGES.NOT_FOUND.code, message: ERROR_MESSAGES.NOT_FOUND.message } }); return makeResponse({ ctr, content: { code: ERROR_MESSAGES.NOT_FOUND.code, message: ERROR_MESSAGES.NOT_FOUND.message } });
+1 -2
View File
@@ -21,8 +21,7 @@ interface AuthContextType {
refresh: () => Promise<void>; refresh: () => Promise<void>;
} }
import { createContext as _createContext } from "react"; export const AuthContext = createContext<AuthContextType>({
export const AuthContext = _createContext<AuthContextType>({
user: null, user: null,
loading: true, loading: true,
refresh: async () => {}, refresh: async () => {},