Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated var's to const/let in server files #920

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions server/plugins/good-hoodie.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
var Transform = require('stream').Transform
var util = require('util')

var log = require('npmlog')
var qs = require('querystring')
const Transform = require('stream').Transform
const util = require('util')
const log = require('npmlog')
const qs = require('querystring')

function HoodieTransform () {
if (!(this instanceof HoodieTransform)) {
Expand All @@ -27,7 +26,7 @@ function transform (data, enc, next) {
}

if (data.event === 'response') {
var path = data.path +
let path = data.path +
(Object.keys(data.query).length ? '?' + qs.stringify(data.query) : '')
log.http(
data.event,
Expand All @@ -41,7 +40,7 @@ function transform (data, enc, next) {
}

if (data.event === 'request' || data.event === 'log') {
var level = findLogLevel(Object.keys(log.levels), data.tags) || 'verbose'
let level = findLogLevel(Object.keys(log.levels), data.tags) || 'verbose'
log[level](
data.event,
new Date(data.timestamp).toISOString(),
Expand All @@ -55,8 +54,8 @@ function transform (data, enc, next) {
}

function findLogLevel (levels, tags) {
for (var i = 0; i < tags.length; i++) {
for (var j = 0; j < levels.length; j++) {
for (let i = 0; i < tags.length; i++) {
for (let j = 0; j < levels.length; j++) {
if (levels[j] === tags[i]) {
tags.splice(i, 1)
return levels[j]
Expand Down
22 changes: 11 additions & 11 deletions server/plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = registerPlugins

var log = require('npmlog')
var requireResolve = require('./resolver')
const log = require('npmlog')
const requireResolve = require('./resolver')

function checkModule (modulePath) {
try {
Expand All @@ -16,11 +16,11 @@ function checkModule (modulePath) {
}

function registerPlugins (server, options, callback) {
var hapiPlugins = [
const hapiPlugins = [
require('inert')
]

var localPlugins = [
let localPlugins = [
'./client',
'./logger',
'./maybe-force-gzip',
Expand All @@ -32,14 +32,14 @@ function registerPlugins (server, options, callback) {
}
})

var externalPlugins = options.plugins
const externalPlugins = options.plugins
.filter(function (pluginPath) {
return checkModule(pluginPath + '/hoodie/server')
})
.map(function (pluginPath) {
var pkg = require(pluginPath + '/package.json')
var pluginName = pkg.hoodie ? pkg.hoodie.name || pkg.name : pkg.name
var hapiPluginOptions = require(pluginPath + '/hoodie/server')
let pkg = require(pluginPath + '/package.json')
let pluginName = pkg.hoodie ? pkg.hoodie.name || pkg.name : pkg.name
let hapiPluginOptions = require(pluginPath + '/hoodie/server')

if (!hapiPluginOptions.register) {
hapiPluginOptions = { register: hapiPluginOptions }
Expand All @@ -51,16 +51,16 @@ function registerPlugins (server, options, callback) {
return hapiPluginOptions
})

var plugins = hapiPlugins.concat(localPlugins, externalPlugins)
const plugins = hapiPlugins.concat(localPlugins, externalPlugins)

log.silly('hapi', 'Registering plugins')
log.silly('hapi', 'Registering plugins :D')

server.register(plugins, function (error) {
if (error) {
return callback(error)
}

log.info('hapi', 'plugins registered')
log.info('hapi', 'plugins registered :D')
callback(null)
})
}
2 changes: 1 addition & 1 deletion server/plugins/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports.register.attributes = {
name: 'hoodie-local-logger'
}

var path = require('path')
const path = require('path')

function register (server, options, next) {
server.register({
Expand Down
36 changes: 18 additions & 18 deletions server/plugins/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ module.exports.register.attributes = {
dependencies: 'inert'
}

var path = require('path')
var requireResolve = require('./resolver')
var createReadStream = require('fs').createReadStream
const path = require('path')
const requireResolve = require('./resolver')
const createReadStream = require('fs').createReadStream

function register (server, options, next) {
var paths = options.paths
var plugins = options.plugins
var publicFolder = paths.public
let paths = options.paths
let plugins = options.plugins
let publicFolder = paths.public

var hoodieVersion
const hoodieVersion
try {
hoodieVersion = require('hoodie/package.json').version
} catch (err) {
hoodieVersion = 'development'
}

var hoodiePublicPath = path.join(requireResolve('../../package.json'), '..', 'public')
var adminPublicPath = path.join(requireResolve('@hoodie/admin/package.json'), '..', 'dist')
var routes = [{
const hoodiePublicPath = path.join(requireResolve('../../package.json'), '..', 'public')
const adminPublicPath = path.join(requireResolve('@hoodie/admin/package.json'), '..', 'dist')
let routes = [{
method: 'GET',
path: '/{p*}',
handler: {
Expand Down Expand Up @@ -79,9 +79,9 @@ function register (server, options, next) {
return
}

var pkg = require(pluginPackagePath)
const pkg = require(pluginPackagePath)

var name = pkg.hoodie ? pkg.hoodie.name || pkg.name : pkg.name
const name = pkg.hoodie ? pkg.hoodie.name || pkg.name : pkg.name

routes.push({
method: 'GET',
Expand All @@ -100,18 +100,18 @@ function register (server, options, next) {

// serve app whenever an html page is requested
// and no other document is available
var app = path.join(publicFolder, 'index.html')
const app = path.join(publicFolder, 'index.html')
server.ext('onPostHandler', function (request, reply) {
var response = request.response
let response = request.response

if (!response.isBoom) {
return reply.continue()
}

var is404 = response.output.statusCode === 404
var isHtmlRequest = /text\/html/.test(request.headers.accept)
var isHoodiePath = /^\/hoodie\//.test(request.path)
var isAdminPublicPath = /^\/hoodie\/admin\//.test(request.path) && !(/^\/hoodie\/admin\/api\//).test(request.path)
const is404 = response.output.statusCode === 404
const isHtmlRequest = /text\/html/.test(request.headers.accept)
const isHoodiePath = /^\/hoodie\//.test(request.path)
const isAdminPublicPath = /^\/hoodie\/admin\//.test(request.path) && !(/^\/hoodie\/admin\/api\//).test(request.path)

if (isAdminPublicPath && isHtmlRequest) {
return reply(createReadStream(path.join(adminPublicPath, 'index.html')))
Expand Down