2023-10-29 19:28:07 +00:00
|
|
|
// Import the framework and instantiate it
|
|
|
|
import Fastify from 'fastify'
|
|
|
|
import fastifyStatic from '@fastify/static'
|
|
|
|
import { routeList } from "./routelist.ts";
|
|
|
|
import { route } from "./util/routewrap.ts";
|
2024-03-31 13:49:09 -07:00
|
|
|
import { git } from './util/git.ts';
|
|
|
|
import path from "path";
|
|
|
|
import {fileURLToPath} from 'url';
|
|
|
|
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
2023-10-29 19:28:07 +00:00
|
|
|
|
2024-03-31 13:49:09 -07:00
|
|
|
await git.clone({
|
2024-03-31 13:55:04 -07:00
|
|
|
from: "https://github.com/thisismypassport/shrinko8",
|
2024-03-31 13:49:09 -07:00
|
|
|
to: path.resolve(__dirname, "shrinko8"),
|
|
|
|
});
|
2023-10-29 19:28:07 +00:00
|
|
|
|
|
|
|
const server = Fastify({
|
|
|
|
logger: true
|
|
|
|
});
|
|
|
|
|
|
|
|
server.register(fastifyStatic, {
|
|
|
|
root: new URL('public', import.meta.url).toString().slice("file://".length),
|
|
|
|
prefix: '/',
|
|
|
|
});
|
|
|
|
|
|
|
|
routeList.forEach(firRoute => {
|
|
|
|
server.route(route(firRoute));
|
2024-03-31 19:40:06 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
server.setNotFoundHandler((req, res) => {
|
|
|
|
if (!req.url.startsWith("/api")) {
|
|
|
|
res.sendFile('index.html');
|
|
|
|
}
|
|
|
|
});
|
2023-10-29 19:28:07 +00:00
|
|
|
|
|
|
|
// Run the server!
|
|
|
|
try {
|
|
|
|
// Note: host needs to be 0.0.0.0 rather than omitted or localhost, otherwise
|
|
|
|
// it always returns an empty reply when used inside docker...
|
|
|
|
// See: https://github.com/fastify/fastify/issues/935
|
|
|
|
await server.listen({ port: parseInt(process.env["PORT"] ?? "3000"), host: "0.0.0.0" })
|
|
|
|
} catch (err) {
|
|
|
|
server.log.error(err)
|
|
|
|
process.exit(1)
|
|
|
|
}
|