Skip to content

Commit

Permalink
fix: dirname
Browse files Browse the repository at this point in the history
  • Loading branch information
bangbang93 committed Jun 9, 2023
1 parent 6b4b07d commit d956032
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {ChildProcess, spawn} from 'child_process'
import colors from 'colors/safe.js'
import express, {type NextFunction, type Request, type Response} from 'express'
import {readFileSync} from 'fs'
import fse from 'fs-extra'
import {chmod, mkdtemp, open, readdir, readFile, rm, stat, unlink} from 'fs/promises'
import fse from 'fs-extra'
import {decompress} from 'fzstd'
import got, {type Got, HTTPError} from 'got'
import {Server} from 'http'
Expand All @@ -19,6 +19,7 @@ import {cwd} from 'process'
import ProgressBar from 'progress'
import {connect, Socket} from 'socket.io-client'
import {Tail} from 'tail'
import {fileURLToPath} from 'url'
import {validateFile} from './file.js'
import MeasureRoute from './measure.route.js'
import {hashToFilename} from './util.js'
Expand All @@ -32,6 +33,8 @@ interface ICounters {
bytes: number
}

const __dirname = dirname(fileURLToPath(import.meta.url))

export class Cluster {
public readonly counters: ICounters = {hits: 0, bytes: 0}
public isEnabled = false
Expand Down Expand Up @@ -194,17 +197,17 @@ export class Cluster {
const dir = await mkdtemp(join(tmpdir(), 'openbmclapi'))
const confFile = `${dir}/nginx/nginx.conf`
const templateFile = 'nginx.conf'
const confTemplate = await readFile(join(process.cwd(), 'nginx', templateFile), 'utf8')
const confTemplate = await readFile(join(__dirname, '..', 'nginx', templateFile), 'utf8')
console.log('nginx conf', confFile)

await fse.copy(join(process.cwd(), 'nginx'), dirname(confFile), {recursive: true, overwrite: true})
await fse.copy(join(__dirname, '..', 'nginx'), dirname(confFile), {recursive: true, overwrite: true})
await fse.outputFile(confFile, template(confTemplate)({
root: pwd,
port: appPort,
ssl: proto === 'https',
}))

const logFile = join(process.cwd(), 'access.log')
const logFile = join(__dirname, '..', 'access.log')
const logFd = await open(logFile, 'a')
await fse.ftruncate(logFd.fd)

Expand Down

0 comments on commit d956032

Please sign in to comment.