|
|
@@ -110,6 +110,38 @@ export const authRoutes = api.route('/api/v1/auth', authRoute)
|
|
|
export const roleRoutes = api.route('/api/v1/roles', rolesRoute)
|
|
|
export const fileApiRoutes = api.route('/api/v1/files', fileRoutes)
|
|
|
|
|
|
+// 代理路由 - 转发到plant2.hbatg.com
|
|
|
+app.all('/plant2/*', async (c) => {
|
|
|
+ const path = c.req.path.replace('/plant2', '')
|
|
|
+ const query = c.req.url.split('?')[1] || ''
|
|
|
+ const targetUrl = `https://plant2.hbatg.com${path}${query ? '?' + query : ''}`
|
|
|
+ console.debug('targetUrl', targetUrl)
|
|
|
+
|
|
|
+ try {
|
|
|
+ const response = await fetch(targetUrl, {
|
|
|
+ method: c.req.method,
|
|
|
+ headers: {
|
|
|
+ // ...Object.fromEntries(c.req.raw.headers),
|
|
|
+ // 'host': 'plant2.hbatg.com'
|
|
|
+ },
|
|
|
+ body: c.req.raw.body
|
|
|
+ })
|
|
|
+
|
|
|
+ const responseBody = await response.text()
|
|
|
+
|
|
|
+ console.debug('responseBody', responseBody)
|
|
|
+
|
|
|
+ // return new Response(responseBody, {
|
|
|
+ // status: response.status,
|
|
|
+ // headers: Object.fromEntries(response.headers)
|
|
|
+ // })
|
|
|
+ return c.text(responseBody, response.status as 200)
|
|
|
+ } catch (error) {
|
|
|
+ console.error('代理请求失败:', error)
|
|
|
+ return c.json({ error: '代理请求失败' }, 500)
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
export type AuthRoutes = typeof authRoutes
|
|
|
export type UserRoutes = typeof userRoutes
|
|
|
export type RoleRoutes = typeof roleRoutes
|