|
@@ -17,14 +17,20 @@ const staticDir = path.join(__dirname, 'public');
|
|
|
// 设置静态文件中间件
|
|
// 设置静态文件中间件
|
|
|
app.use(express.static(staticDir, {
|
|
app.use(express.static(staticDir, {
|
|
|
// 缓存控制(1天)
|
|
// 缓存控制(1天)
|
|
|
- maxAge: '1d',
|
|
|
|
|
|
|
+ //maxAge: '1d',
|
|
|
|
|
+ maxAge: 0,
|
|
|
|
|
+ cacheControl: false,
|
|
|
|
|
+ etag: false,
|
|
|
|
|
+ lastModified: false,
|
|
|
// 设置索引文件
|
|
// 设置索引文件
|
|
|
index: ['index.html', 'index.htm'],
|
|
index: ['index.html', 'index.htm'],
|
|
|
// 自定义文件类型处理
|
|
// 自定义文件类型处理
|
|
|
setHeaders: (res, filePath) => {
|
|
setHeaders: (res, filePath) => {
|
|
|
const contentType = mime.contentType(path.extname(filePath)) || 'application/octet-stream';
|
|
const contentType = mime.contentType(path.extname(filePath)) || 'application/octet-stream';
|
|
|
res.setHeader('Content-Type', contentType);
|
|
res.setHeader('Content-Type', contentType);
|
|
|
-
|
|
|
|
|
|
|
+ res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
|
|
|
|
|
+ res.setHeader('Pragma', 'no-cache');
|
|
|
|
|
+ res.setHeader('Expires', '0');
|
|
|
// 为特定文件类型添加额外头信息
|
|
// 为特定文件类型添加额外头信息
|
|
|
if (filePath.endsWith('.css')) {
|
|
if (filePath.endsWith('.css')) {
|
|
|
res.setHeader('X-Content-Type-Options', 'nosniff');
|
|
res.setHeader('X-Content-Type-Options', 'nosniff');
|
|
@@ -47,4 +53,4 @@ var httpsserver = http.createServer(httpsOption, app);
|
|
|
app.use('/api', router);
|
|
app.use('/api', router);
|
|
|
|
|
|
|
|
httpsserver.listen(port);
|
|
httpsserver.listen(port);
|
|
|
-console.log("Server running at http://" + host + ":" + port + "/");
|
|
|
|
|
|
|
+console.log("Server running at http://" + host + ":" + port + "/");
|