Skip to content

Commit 1379b15

Browse files
authored
feat: set statics file cache control (#580)
Signed-off-by: Bob Du <i@bobdu.cc>
1 parent b27b1de commit 1379b15

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

service/src/index.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as path from 'node:path'
12
import express from 'express'
23
import jwt from 'jsonwebtoken'
34
import * as dotenv from 'dotenv'
@@ -58,7 +59,15 @@ dotenv.config()
5859
const app = express()
5960
const router = express.Router()
6061

61-
app.use(express.static('public'))
62+
app.use(express.static('public', {
63+
setHeaders: (res, filePath) => {
64+
if (path.extname(filePath) === '.html')
65+
res.setHeader('Cache-Control', 'public, max-age=0')
66+
else
67+
res.setHeader('Cache-Control', 'public, max-age=31536000')
68+
},
69+
}))
70+
6271
app.use(express.json())
6372

6473
app.use('/uploads', express.static('uploads'))

0 commit comments

Comments
 (0)