app: add Cache-Control header

This commit is contained in:
DIYgod 2018-06-02 17:22:56 +08:00
parent 16bc48b723
commit 36e565d388
No known key found for this signature in database
GPG Key ID: EC0B76A252D3EF67
1 changed files with 2 additions and 0 deletions

View File

@ -1,4 +1,5 @@
const logger = require('../utils/logger');
const config = require('../config');
module.exports = async (ctx, next) => {
logger.info(`${ctx.url}, user IP: ${ctx.ips[0] || ctx.ip}`);
@ -8,6 +9,7 @@ module.exports = async (ctx, next) => {
'Access-Control-Allow-Headers': 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild',
'Access-Control-Allow-Methods': 'PUT, POST, GET, DELETE, OPTIONS',
'Content-Type': 'application/xml; charset=utf-8',
'Cache-Control': `max-age=${config.cacheExpire}`,
};
ctx.set(headers);
await next();