Skip to content

Commit

Permalink
fix: gateway cannot dispatch home
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain committed May 9, 2024
1 parent f073062 commit 8babd19
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"watch:node": "hereby",
"dev": "hereby",
"dev:node": "nodemon ./dist/node",
"dev:node:debug": "nodemon --inspect --inspect-brk ./dist/node",
"dev:worker:preview": "run-p dev:worker dev:proxy",
"dev:worker": "wrangler dev",
"dev:proxy": "tsx dev.ts",
Expand Down
13 changes: 1 addition & 12 deletions src/api/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,6 @@ const OpenSumiRunHome = {
},
};

const githubBotControllers = [
SimpleHome,
Ding,
GitHub,
Proxy,
Webhook,
Static,
Configuration,
Auth,
] as ControllerFacade[];

const applyBaseController = (hono: THono) => {
hono.get('/favicon.ico', async (c) => {
return c.body(favicon, 200, {
Expand All @@ -50,7 +39,7 @@ const applyBaseController = (hono: THono) => {
};

const controllers = {
'': githubBotControllers,
'': [SimpleHome, Ding, GitHub, Proxy, Webhook, Static, Configuration, Auth],
[ERuleName.Run]: [
OpenSumiRunWithIDEPrefix,
OpenSumiRun,
Expand Down
7 changes: 4 additions & 3 deletions src/api/gateway.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { getPath } from 'hono/utils/url';
import { getPath, mergePath } from 'hono/utils/url';

export enum ERuleName {
Run = '/run',
Run = '/run/',
}

const rules = {
'opensumi.run': ERuleName.Run,
'github.opensumi.run': ERuleName.Run,
'local.opensumi.run': ERuleName.Run,
} as Record<string, ERuleName>;

export function dispatch(request: Request) {
Expand All @@ -15,7 +16,7 @@ export function dispatch(request: Request) {

const path = rules[hostname];
if (path) {
return path + rawPath;
return mergePath(path, rawPath);
}
return rawPath;
}
5 changes: 4 additions & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import { logger } from './middleware/logger';
export function ignition() {
const hono = new Hono({
getPath(request: Request) {
return dispatch(request);
const target = dispatch(request);
console.log(`[dispatch] ${request.url} ->`, target);

return target;
},
}) as THono;

Expand Down

0 comments on commit 8babd19

Please sign in to comment.