Skip to content

Commit

Permalink
Fix local file server shutdown (#9312)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielBelmes committed Nov 21, 2023
1 parent 21618f9 commit d9f8081
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions packages/server-core/src/media/storageprovider/local.storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit d9f8081

Please sign in to comment.