mirror of https://github.com/certd/certd
perf: 优化缩短首页缓存时间
parent
480ce2d812
commit
49395e8cb6
|
@ -2,7 +2,7 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<link rel="icon" href="/static/logo.svg"/>
|
||||
<link rel="icon" href="/static/images/logo/logo.svg"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
<title>Loading</title>
|
||||
<script src="/static/icons/iconfont.js"></script>
|
||||
|
|
|
@ -1 +1 @@
|
|||
1
|
||||
certd server is ready
|
||||
|
|
|
@ -4,7 +4,6 @@ import { MidwayConfig } from '@midwayjs/core';
|
|||
// import { fileURLToPath } from 'node:url';
|
||||
// // const __filename = fileURLToPath(import.meta.url);
|
||||
// const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
// eslint-disable-next-line node/no-extraneous-import
|
||||
import { FlywayHistory } from '@certd/midway-flyway-js';
|
||||
import { UserEntity } from '../modules/sys/authority/entity/user.js';
|
||||
|
@ -15,8 +14,9 @@ import { mergeConfig } from './loader.js';
|
|||
import { libServerEntities } from '@certd/lib-server';
|
||||
import { commercialEntities } from '@certd/commercial-core';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { uploadWhiteList, DefaultUploadFileMimeType } from '@midwayjs/upload';
|
||||
import { DefaultUploadFileMimeType, uploadWhiteList } from '@midwayjs/upload';
|
||||
import path from 'path';
|
||||
|
||||
const env = process.env.NODE_ENV || 'development';
|
||||
|
||||
const development = {
|
||||
|
@ -27,7 +27,7 @@ const development = {
|
|||
staticFile: {
|
||||
usePrecompiledGzip: true,
|
||||
buffer: true,
|
||||
maxAge: 30 * 24 * 60 * 60 * 1000,
|
||||
maxAge: 30 * 24 * 60 * 60,
|
||||
gzip: true,
|
||||
dirs: {
|
||||
default: {
|
||||
|
@ -35,14 +35,10 @@ const development = {
|
|||
dir: 'public',
|
||||
alias: {
|
||||
'/': '/index.html',
|
||||
'\\': '/index.html',
|
||||
},
|
||||
maxFiles: 200,
|
||||
},
|
||||
// '/index.html': {
|
||||
// maxAge: 0,
|
||||
// },
|
||||
// '/': {
|
||||
// maxAge: 0,
|
||||
// },
|
||||
},
|
||||
},
|
||||
cron: {
|
||||
|
|
|
@ -18,6 +18,7 @@ import * as libServer from '@certd/lib-server';
|
|||
import * as commercial from '@certd/commercial-core';
|
||||
import * as upload from '@midwayjs/upload';
|
||||
import { setLogger } from '@certd/acme-client';
|
||||
import { IMidwayKoaContext, NextFunction } from '@midwayjs/koa';
|
||||
process.on('uncaughtException', error => {
|
||||
console.error('未捕获的异常:', error);
|
||||
// 在这里可以添加日志记录、发送错误通知等操作
|
||||
|
@ -61,6 +62,15 @@ export class MainConfiguration {
|
|||
origin: '*',
|
||||
})
|
||||
);
|
||||
//
|
||||
// this.app.use(async (ctx, next) => {
|
||||
// // 只在返回 'index.html' 的时候设置 maxAge
|
||||
// if (ctx.path === '/') {
|
||||
// // ctx.response.redirect('/index.html');
|
||||
// ctx.send(file)
|
||||
// return;
|
||||
// }
|
||||
// });
|
||||
// bodyparser options see https://github.com/koajs/bodyparser
|
||||
//this.app.use(bodyParser());
|
||||
//请求日志打印
|
||||
|
@ -76,6 +86,13 @@ export class MainConfiguration {
|
|||
ResetPasswdMiddleware,
|
||||
]);
|
||||
|
||||
this.app.getMiddleware().insertFirst(async (ctx: IMidwayKoaContext, next: NextFunction) => {
|
||||
await next();
|
||||
if (ctx.path === '/' || ctx.path === '/index.html') {
|
||||
ctx.response.set('Cache-Control', 'public,max-age=180');
|
||||
}
|
||||
});
|
||||
|
||||
//acme setlogger
|
||||
setLogger((text: string) => {
|
||||
logger.info(text);
|
||||
|
|
Loading…
Reference in New Issue