app: move some variables outside module.exports for a better performance
This commit is contained in:
parent
2f9fc20285
commit
f5b4874ba7
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue