@ -163,7 +163,33 @@ const Caddyfile = `\
# 清注意在防火墙/安全组中放行端口,且部分运营商会拦截未经备案的域名。
# For more information, refer to caddy v2 documentation.
:80 {
reverse_proxy http://127.0.0.1:8888
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 {
handle @notStatic {
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);