Skip to content

Commit

Permalink
chore(server): Convert PromiseContainer to object and remove (karma-r…
Browse files Browse the repository at this point in the history
…unner#3401)

initializeMimeTypes.
  • Loading branch information
anthony-redFox authored Feb 24, 2020
1 parent 0856234 commit 9eb6436
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
10 changes: 0 additions & 10 deletions lib/middleware/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
'use strict'

const mime = require('mime')
const _ = require('lodash')
const parseRange = require('range-parser')
const Buffer = require('safe-buffer').Buffer
const log = require('../logger').create('web-server')
Expand Down Expand Up @@ -100,14 +99,6 @@ function setHeavyCacheHeaders (response) {
response.setHeader('Cache-Control', 'public, max-age=31536000')
}

function initializeMimeTypes (config) {
if (config && config.mime) {
_.forEach(config.mime, (value, key) => {
mime.define({ [key]: value }, true)
})
}
}

class PromiseContainer {
constructor () {
this.promise = null
Expand All @@ -127,5 +118,4 @@ exports.PromiseContainer = PromiseContainer
exports.createServeFile = createServeFile
exports.setNoCacheHeaders = setNoCacheHeaders
exports.setHeavyCacheHeaders = setHeavyCacheHeaders
exports.initializeMimeTypes = initializeMimeTypes
exports.serve404 = serve404
18 changes: 10 additions & 8 deletions lib/web-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const http = require('http')
const https = require('https')
const path = require('path')
const connect = require('connect')
const Promise = require('bluebird')
const mimeType = require('mime')

const common = require('./middleware/common')
const runnerMiddleware = require('./middleware/runner')
Expand All @@ -28,15 +28,16 @@ function createCustomHandler (customFileHandlers, config) {
createCustomHandler.$inject = ['customFileHandlers', 'config']

function createFilesPromise (emitter, fileList) {
const filesPromise = new common.PromiseContainer()

// Set an empty list of files to avoid race issues with
// file_list_modified not having been emitted yet
filesPromise.set(Promise.resolve(fileList.files))

emitter.on('file_list_modified', (files) => filesPromise.set(Promise.resolve(files)))
let files = fileList.files
emitter.on('file_list_modified', (filesParam) => { files = filesParam })

return filesPromise
return {
then (...args) {
return Promise.resolve(files).then(...args)
}
}
}

function createServeStaticFile (config) {
Expand All @@ -50,7 +51,8 @@ function createServeFile (config) {
createServeFile.$inject = ['config']

function createWebServer (injector, config) {
common.initializeMimeTypes(config)
const { mime = {} } = config
mimeType.define({ ...mime }, true)

const proxyMiddlewareInstance = injector.invoke(proxyMiddleware.create)

Expand Down

0 comments on commit 9eb6436

Please sign in to comment.