Skip to content

Commit

Permalink
feat: set statics file cache control (#580)
Browse files Browse the repository at this point in the history
Signed-off-by: Bob Du <[email protected]>
  • Loading branch information
BobDu authored Oct 25, 2024
1 parent b27b1de commit 1379b15
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion service/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as path from 'node:path'
import express from 'express'
import jwt from 'jsonwebtoken'
import * as dotenv from 'dotenv'
Expand Down Expand Up @@ -58,7 +59,15 @@ dotenv.config()
const app = express()
const router = express.Router()

app.use(express.static('public'))
app.use(express.static('public', {
setHeaders: (res, filePath) => {
if (path.extname(filePath) === '.html')
res.setHeader('Cache-Control', 'public, max-age=0')
else
res.setHeader('Cache-Control', 'public, max-age=31536000')
},
}))

app.use(express.json())

app.use('/uploads', express.static('uploads'))
Expand Down

0 comments on commit 1379b15

Please sign in to comment.