mirror of
https://github.com/viarotel-org/escrcpy.git
synced 2024-11-28 01:10:53 +01:00
46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
import { relative } from 'node:path'
|
|
import { Hono } from 'hono'
|
|
import { serve } from '@hono/node-server'
|
|
import { serveStatic } from '@hono/node-server/serve-static'
|
|
import createWebSocketServer from './wss/index'
|
|
|
|
export default async (mainWindow) => {
|
|
const app = new Hono()
|
|
|
|
app.notFound((c) => {
|
|
return c.text('Escrcpy copilot 404', 404)
|
|
})
|
|
|
|
const VITE_DEV_SERVER_URL = process.env.VITE_DEV_SERVER_URL
|
|
|
|
if (VITE_DEV_SERVER_URL) {
|
|
app.get('/', (ctx) => {
|
|
return ctx.redirect(`${VITE_DEV_SERVER_URL}copilot/index.html`)
|
|
})
|
|
}
|
|
else {
|
|
app.use(
|
|
'/*',
|
|
serveStatic({
|
|
root: relative('./', process.env.DIST),
|
|
rewriteRequestPath: (path) => {
|
|
return path.replace(/^\//, '/copilot')
|
|
},
|
|
}),
|
|
)
|
|
app.use(
|
|
'/assets/*',
|
|
serveStatic({
|
|
root: relative('./', `${process.env.DIST}/assets/`),
|
|
rewriteRequestPath: (path) => {
|
|
return path.replace(/^\/assets/, '/')
|
|
},
|
|
}),
|
|
)
|
|
}
|
|
|
|
createWebSocketServer()
|
|
|
|
serve({ fetch: app.fetch, port: 1996 })
|
|
}
|