app: move some variables outside module.exports for a better performance

This commit is contained in:
DIYgod 2018-06-02 17:31:33 +08:00
parent 2f9fc20285
commit f5b4874ba7
No known key found for this signature in database
GPG Key ID: EC0B76A252D3EF67
2 changed files with 9 additions and 11 deletions

View File

@ -1,10 +1,9 @@
const art = require('art-template');
const path = require('path');
const blacklist = (process.env.BLACKLIST && process.env.BLACKLIST.split(',')) || [];
const whitelist = process.env.WHITELIST && process.env.WHITELIST.split(',');
module.exports = async (ctx, next) => {
const blacklist = (process.env.BLACKLIST && process.env.BLACKLIST.split(',')) || [];
const whitelist = process.env.WHITELIST && process.env.WHITELIST.split(',');
const ip = ctx.ips[0] || ctx.ip;
const requestPath = ctx.request.path;

View File

@ -1,16 +1,15 @@
const logger = require('../utils/logger');
const config = require('../config');
const headers = {
'Access-Control-Allow-Origin': '*',
'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 / 2}`,
};
module.exports = async (ctx, next) => {
logger.info(`${ctx.url}, user IP: ${ctx.ips[0] || ctx.ip}`);
const headers = {
'Access-Control-Allow-Origin': '*',
'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 / 2}`,
};
ctx.set(headers);
await next();
};