core: generate static directory

pull/547/head
undefined 2 years ago
parent 1251b76e0f
commit c2928dfbfb
No known key found for this signature in database

@ -163,7 +163,33 @@ const Caddyfile = `\
# /
# For more information, refer to caddy v2 documentation.
:80 {
log {
output file /data/access.log {
roll_size 1gb
roll_keep_for 72h
}
format json
}
# Handle static files directly, for better performance.
root * /root/.hydro/static
@static {
file {
try_files {path}
}
}
@notStatic {
not {
file {
try_files {path}
}
}
}
handle @notStatic {
reverse_proxy http://127.0.0.1:8888
}
handle @static {
file_server
}
}
`;

@ -93,6 +93,12 @@ export async function apply(ctx: Context) {
}
}
}
for (const f of global.addons) {
const dir = path.join(f, 'public');
// eslint-disable-next-line no-await-in-loop
if (await fs.pathExists(dir)) await fs.copy(dir, '/root/.hydro/static');
}
await ctx.parallel('app/listen');
logger.success('Server started');
process.send?.('ready');
await ctx.parallel('app/ready');

@ -32,6 +32,7 @@ type HandlerEvents =
/* eslint-disable @typescript-eslint/naming-convention */
export interface EventMap extends LifecycleEvents, HandlerEvents {
'app/started': () => void
'app/listen': () => void
'app/ready': () => VoidReturn
'app/exit': () => VoidReturn
'app/before-reload': (entries: Set<string>) => VoidReturn

@ -556,7 +556,7 @@ ${ctx.response.status} ${endTime - startTime}ms ${ctx.response.length}`);
socket.close();
});
const port = system.get('server.port');
pluginContext.on('app/ready', async () => {
pluginContext.on('app/listen', async () => {
await new Promise((r) => {
httpServer.listen(argv.options.port || port, () => {
logger.success('Server listening at: %d', argv.options.port || port);

Loading…
Cancel
Save