feat: use const/let

v1.18.x
Barış Soner Uşaklı 4 years ago
parent 4588e52120
commit 6fc31df033

@ -1,16 +1,16 @@
'use strict'; 'use strict';
var os = require('os'); const os = require('os');
var winston = require('winston'); const winston = require('winston');
var _ = require('lodash'); const _ = require('lodash');
var meta = require('../meta'); const meta = require('../meta');
var languages = require('../languages'); const languages = require('../languages');
var helpers = require('./helpers'); const helpers = require('./helpers');
module.exports = function (middleware) { module.exports = function (middleware) {
middleware.addHeaders = helpers.try(function addHeaders(req, res, next) { middleware.addHeaders = helpers.try(function addHeaders(req, res, next) {
var headers = { const headers = {
'X-Powered-By': encodeURI(meta.config['powered-by'] || 'NodeBB'), 'X-Powered-By': encodeURI(meta.config['powered-by'] || 'NodeBB'),
'X-Frame-Options': meta.config['allow-from-uri'] ? 'ALLOW-FROM ' + encodeURI(meta.config['allow-from-uri']) : 'SAMEORIGIN', 'X-Frame-Options': meta.config['allow-from-uri'] ? 'ALLOW-FROM ' + encodeURI(meta.config['allow-from-uri']) : 'SAMEORIGIN',
'Access-Control-Allow-Methods': encodeURI(meta.config['access-control-allow-methods'] || ''), 'Access-Control-Allow-Methods': encodeURI(meta.config['access-control-allow-methods'] || ''),
@ -18,7 +18,7 @@ module.exports = function (middleware) {
}; };
if (meta.config['access-control-allow-origin']) { if (meta.config['access-control-allow-origin']) {
var origins = meta.config['access-control-allow-origin'].split(','); let origins = meta.config['access-control-allow-origin'].split(',');
origins = origins.map(function (origin) { origins = origins.map(function (origin) {
return origin && origin.trim(); return origin && origin.trim();
}); });
@ -29,7 +29,7 @@ module.exports = function (middleware) {
} }
if (meta.config['access-control-allow-origin-regex']) { if (meta.config['access-control-allow-origin-regex']) {
var originsRegex = meta.config['access-control-allow-origin-regex'].split(','); let originsRegex = meta.config['access-control-allow-origin-regex'].split(',');
originsRegex = originsRegex.map(function (origin) { originsRegex = originsRegex.map(function (origin) {
try { try {
origin = new RegExp(origin.trim()); origin = new RegExp(origin.trim());
@ -55,7 +55,7 @@ module.exports = function (middleware) {
headers['X-Upstream-Hostname'] = os.hostname(); headers['X-Upstream-Hostname'] = os.hostname();
} }
for (var key in headers) { for (const key in headers) {
if (headers.hasOwnProperty(key) && headers[key]) { if (headers.hasOwnProperty(key) && headers[key]) {
res.setHeader(key, headers[key]); res.setHeader(key, headers[key]);
} }

Loading…
Cancel
Save