escrcpy/electron/copilot/index.js

44 lines
1.0 KiB
JavaScript
Raw Normal View History

2023-11-17 11:42:50 +01:00
import { relative } from 'node:path'
import { Hono } from 'hono'
import { serve } from '@hono/node-server'
import { serveStatic } from '@hono/node-server/serve-static'
export default async (mainWindow) => {
const app = new Hono()
app.notFound((c) => {
2023-11-21 09:37:02 +01:00
return c.text('Escrcpy copilot 404', 404)
2023-11-17 11:42:50 +01:00
})
const VITE_DEV_SERVER_URL = process.env.VITE_DEV_SERVER_URL
if (VITE_DEV_SERVER_URL) {
app.get('/', ctx =>
2023-11-21 09:37:02 +01:00
ctx.redirect(`${VITE_DEV_SERVER_URL}copilot/index.html`),
2023-11-17 11:42:50 +01:00
)
}
else {
app.use(
'/*',
serveStatic({
root: relative('./', process.env.DIST),
rewriteRequestPath: (path) => {
2023-11-21 09:37:02 +01:00
return path.replace(/^\//, '/copilot')
2023-11-17 11:42:50 +01:00
},
}),
)
app.use(
'/assets/*',
serveStatic({
root: relative('./', `${process.env.DIST}/assets/`),
rewriteRequestPath: (path) => {
console.log('path', path)
return path.replace(/^\/assets/, '/')
},
}),
)
}
serve({ fetch: app.fetch, port: 1996 })
}