Skip to content

Commit

Permalink
feat: 静态资源增加强缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
zonemeen committed Mar 13, 2024
1 parent 9185612 commit fd7b901
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion public/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
height: calc(100vh - 236px);
}
.ant-input-search {
width: 220px;
width: 240px;
}
.list-item-click {
cursor: pointer;
Expand Down
14 changes: 11 additions & 3 deletions src/qrcode/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import express, { NextFunction, Request, Response } from 'express'
import search from '../services/search'
import lyricDownload from '../services/lyric'
import { getNetworkAddress } from '../utils'
import { version } from '../../package.json'
import type { ServiceType, CommandOptions } from '../types'

interface DownloadRequestType {
Expand Down Expand Up @@ -49,11 +50,18 @@ export default async (options: CommandOptions) => {

let htmlContent = readFileSync(indexPath, 'utf8')

htmlContent = htmlContent.replace(/{{base}}/g, base?.length ? `/${base}` : '')
htmlContent = htmlContent
.replace(/{{base}}/g, base?.length ? `/${base}` : '')
.replace(/{{version}}/g, version)

app.use(
`/${base}`,
express.static(resolve(__dirname, process.env.IS_DEV === 'true' ? '../../public' : '../public'))
`${base?.length ? `/${base}` : ''}/${version}`,
express.static(
resolve(__dirname, process.env.IS_DEV === 'true' ? '../../public' : '../public'),
{
maxAge: 31536000,
}
)
)

app.get(`/${base}`, (_, res) => {
Expand Down
6 changes: 3 additions & 3 deletions template/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<title>Music Player</title>
<link rel="icon" type="image/svg+xml" href="{{base}}/music.svg" />
<link rel="icon" type="image/png" href="{{base}}/music.png" />
<link rel="icon" type="image/svg+xml" href="{{base}}/{{version}}/music.svg" />
<link rel="icon" type="image/png" href="{{base}}/{{version}}/music.png" />
<link
href="https://cdn.bootcdn.net/ajax/libs/ant-design-vue/1.7.7/antd.min.css"
rel="stylesheet"
Expand All @@ -14,7 +14,7 @@
href="https://cdn.bootcdn.net/ajax/libs/aplayer/1.10.1/APlayer.min.css"
rel="stylesheet"
/>
<link href="{{base}}/index.css" rel="stylesheet" />
<link href="{{base}}/{{version}}/index.css" rel="stylesheet" />
<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.9/vue.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/ant-design-vue/1.7.7/antd.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/aplayer/1.10.1/APlayer.min.js"></script>
Expand Down

0 comments on commit fd7b901

Please sign in to comment.