-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use elysiajs to provide static files
- Loading branch information
Showing
7 changed files
with
38 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,20 @@ | ||
import { PrismaClient } from '@prisma/client' | ||
import { execFile, ExecFileException } from 'child_process' | ||
import { Elysia } from 'elysia' | ||
import { staticPlugin } from '@elysiajs/static' | ||
|
||
const prisma = new PrismaClient() | ||
|
||
const servers = await prisma.server.findMany() | ||
|
||
const getData = domain => { | ||
return new Promise<{ | ||
error: ExecFileException | null | ||
stdout: string | ||
stderr: string | ||
}>(resolve => { | ||
execFile( | ||
'./service/vlmcs/vlmcs-darwin', | ||
[`${domain}:${1688}`, `-${6}`, `-l ${1}`], | ||
{ timeout: 5 * 1000 }, | ||
(error, stdout, stderr) => resolve({ error, stdout, stderr }), | ||
) | ||
new Elysia() | ||
// .use( | ||
// staticPlugin({ | ||
// assets: 'dist/assets', | ||
// prefix: '/assets', | ||
// }), | ||
// ) | ||
// .get('/*', () => Bun.file('dist/index.html')) | ||
.onError(ctx => { | ||
if (ctx.code === 'NOT_FOUND') { | ||
ctx.set.redirect = '/' | ||
return '' | ||
} | ||
}) | ||
} | ||
|
||
servers.map(async item => { | ||
const result = await getData(item.address) | ||
console.log(result) | ||
}) | ||
.use(staticPlugin({ assets: 'dist', prefix: '/' })) | ||
.get('/', () => Bun.file('dist/index.html')) | ||
.listen(3000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters