Refactor server structure and enhance middleware functionality
- Consolidated middleware setup into a dedicated setup file for better organization. - Introduced API proxy middleware to handle requests to the backend API. - Registered well-known, merge, and SSR routes in separate files for improved modularity. - Removed unused HTML and SSR layout files to streamline the codebase. - Implemented a utility for HTML escaping to prevent XSS vulnerabilities. - Updated the main server entry point to utilize the new middleware and route structure.
This commit is contained in:
20
src/server/middlewares/setup.ts
Normal file
20
src/server/middlewares/setup.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { contextStorage } from 'hono/context-storage';
|
||||
import { cors } from 'hono/cors';
|
||||
import isMobile from 'is-mobile';
|
||||
import type { Hono } from 'hono';
|
||||
|
||||
export function setupMiddlewares(app: Hono) {
|
||||
app.use('*', contextStorage());
|
||||
|
||||
app.use(cors(), async (c, next) => {
|
||||
c.set("fetch", app.request.bind(app));
|
||||
|
||||
const ua = c.req.header("User-Agent");
|
||||
if (!ua) {
|
||||
return c.json({ error: "User-Agent header is missing" }, 400);
|
||||
}
|
||||
|
||||
c.set("isMobile", isMobile({ ua }));
|
||||
await next();
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user