From 9eb6436b8bf3145d1f7b637dc719ffd0b9122bc1 Mon Sep 17 00:00:00 2001 From: Anton Date: Mon, 24 Feb 2020 20:38:17 +0300 Subject: [PATCH] chore(server): Convert PromiseContainer to object and remove (#3401) initializeMimeTypes. --- lib/middleware/common.js | 10 ---------- lib/web-server.js | 18 ++++++++++-------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/lib/middleware/common.js b/lib/middleware/common.js index a04d23d99..eb1035a0c 100644 --- a/lib/middleware/common.js +++ b/lib/middleware/common.js @@ -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') @@ -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 @@ -127,5 +118,4 @@ exports.PromiseContainer = PromiseContainer exports.createServeFile = createServeFile exports.setNoCacheHeaders = setNoCacheHeaders exports.setHeavyCacheHeaders = setHeavyCacheHeaders -exports.initializeMimeTypes = initializeMimeTypes exports.serve404 = serve404 diff --git a/lib/web-server.js b/lib/web-server.js index 3f271d3bc..a348f9421 100644 --- a/lib/web-server.js +++ b/lib/web-server.js @@ -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') @@ -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) { @@ -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)