From d9f808115b85d20bafdbe4d26eef66479ae22405 Mon Sep 17 00:00:00 2001 From: Daniel Belmes <3631206+DanielBelmes@users.noreply.github.com> Date: Mon, 20 Nov 2023 18:43:56 -0800 Subject: [PATCH] Fix local file server shutdown (#9312) --- .../media/storageprovider/local.storage.ts | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/server-core/src/media/storageprovider/local.storage.ts b/packages/server-core/src/media/storageprovider/local.storage.ts index 25423227830..8c48e9f74b1 100755 --- a/packages/server-core/src/media/storageprovider/local.storage.ts +++ b/packages/server-core/src/media/storageprovider/local.storage.ts @@ -34,6 +34,7 @@ import { MULTIPART_CUTOFF_SIZE } from '@etherealengine/common/src/constants/File import { FileBrowserContentType } from '@etherealengine/engine/src/schemas/media/file-browser.schema' import { getState } from '@etherealengine/hyperflux' +import { ChildProcess } from 'child_process' import logger from '../../ServerLogger' import { ServerMode, ServerState } from '../../ServerState' import config from '../../appconfig' @@ -81,9 +82,30 @@ export class LocalStorage implements StorageProviderInterface { this._store = fsStore(this.PATH_PREFIX) if (getState(ServerState).serverMode === ServerMode.API && !config.testEnabled) { - require('child_process').spawn('npm', ['run', 'serve-local-files'], { - cwd: process.cwd(), - stdio: 'inherit' + const child: ChildProcess = require('child_process').spawn( + 'npx', + [ + 'http-server', + `${this.PATH_PREFIX}`, + '--ssl', + '--cert', + `${config.server.certPath}`, + '--key', + `${config.server.keyPath}`, + '--port', + '8642', + '--cors=*', + '--brotli', + '--gzip' + ], + { + cwd: process.cwd(), + stdio: 'inherit', + detached: true + } + ) + process.on('exit', async () => { + process.kill(-child.pid!, 'SIGINT') }) } this.getOriginURLs().then((result) => (this.originURLs = result))