Skip to content

Commit 3c4a33f

Browse files
committed
feat(hono-plugin): add support for static files and SPA fallback configuration
1 parent 5ba5c6f commit 3c4a33f

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

packages/plugins/plugin-hono-server/src/hono-plugin.test.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,23 @@ vi.mock('@objectstack/hono', () => ({
99
createHonoApp: vi.fn(),
1010
}));
1111

12+
vi.mock('@hono/node-server/serve-static', () => ({
13+
serveStatic: vi.fn(() => (c: any, next: any) => next())
14+
}));
15+
1216
vi.mock('./adapter', () => ({
1317
HonoHttpServer: vi.fn(function() {
1418
return {
1519
mount: vi.fn(),
1620
start: vi.fn(),
1721
stop: vi.fn(),
18-
getApp: vi.fn()
22+
getApp: vi.fn(),
23+
listen: vi.fn(),
24+
getPort: vi.fn().mockReturnValue(3000),
25+
close: vi.fn(),
26+
getRawApp: vi.fn().mockReturnValue({
27+
get: vi.fn(),
28+
})
1929
};
2030
})
2131
}));
@@ -104,4 +114,23 @@ describe('HonoServerPlugin', () => {
104114

105115
expect(logger.error).toHaveBeenCalledWith('Failed to create standard Hono app', expect.any(Error));
106116
});
117+
118+
it('should configure static files and SPA fallback when enabled', async () => {
119+
const plugin = new HonoServerPlugin({
120+
staticRoot: './public',
121+
spaFallback: true
122+
});
123+
124+
await plugin.init(context as PluginContext);
125+
await plugin.start(context as PluginContext);
126+
127+
const serverInstance = (HonoHttpServer as any).mock.instances[0];
128+
const rawApp = serverInstance.getRawApp();
129+
130+
expect(serverInstance.getRawApp).toHaveBeenCalled();
131+
// Should register static files middleware
132+
expect(rawApp.get).toHaveBeenCalledWith('/*', expect.anything());
133+
// Should register SPA fallback middleware
134+
expect(rawApp.get).toHaveBeenCalledWith('*', expect.anything());
135+
});
107136
});

0 commit comments

Comments
 (0)