mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
core: generate static directory
This commit is contained in:
4 files changed
+34
-1
No files matched your search
@@ -163,8 +163,34 @@ const Caddyfile = `\
|
|||||||
# 清注意在防火墙/安全组中放行端口,且部分运营商会拦截未经备案的域名。
|
# 清注意在防火墙/安全组中放行端口,且部分运营商会拦截未经备案的域名。
|
||||||
# For more information, refer to caddy v2 documentation.
|
# For more information, refer to caddy v2 documentation.
|
||||||
:80 {
|
: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
|
reverse_proxy http://127.0.0.1:8888
|
||||||
}
|
}
|
||||||
|
handle @static {
|
||||||
|
file_server
|
||||||
|
}
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const judgeYaml = `\
|
const judgeYaml = `\
|
||||||
|
|||||||
@@ -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');
|
logger.success('Server started');
|
||||||
process.send?.('ready');
|
process.send?.('ready');
|
||||||
await ctx.parallel('app/ready');
|
await ctx.parallel('app/ready');
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ type HandlerEvents =
|
|||||||
/* eslint-disable @typescript-eslint/naming-convention */
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
export interface EventMap extends LifecycleEvents, HandlerEvents {
|
export interface EventMap extends LifecycleEvents, HandlerEvents {
|
||||||
'app/started': () => void
|
'app/started': () => void
|
||||||
|
'app/listen': () => void
|
||||||
'app/ready': () => VoidReturn
|
'app/ready': () => VoidReturn
|
||||||
'app/exit': () => VoidReturn
|
'app/exit': () => VoidReturn
|
||||||
'app/before-reload': (entries: Set<string>) => VoidReturn
|
'app/before-reload': (entries: Set<string>) => VoidReturn
|
||||||
|
|||||||
@@ -556,7 +556,7 @@ ${ctx.response.status} ${endTime - startTime}ms ${ctx.response.length}`);
|
|||||||
socket.close();
|
socket.close();
|
||||||
});
|
});
|
||||||
const port = system.get('server.port');
|
const port = system.get('server.port');
|
||||||
pluginContext.on('app/ready', async () => {
|
pluginContext.on('app/listen', async () => {
|
||||||
await new Promise((r) => {
|
await new Promise((r) => {
|
||||||
httpServer.listen(argv.options.port || port, () => {
|
httpServer.listen(argv.options.port || port, () => {
|
||||||
logger.success('Server listening at: %d', argv.options.port || port);
|
logger.success('Server listening at: %d', argv.options.port || port);
|
||||||
|
|||||||
Reference in new issue
Block a user