From 60c2451910564dea6a48e21ceed3e13b49ecb0fd Mon Sep 17 00:00:00 2001 From: bangbang93 Date: Tue, 30 Jan 2024 16:51:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=B0=83=E6=95=B4sock=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- nginx/nginx.conf | 5 +++-- src/cluster.ts | 11 +++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 21a9b4a..00a8f03 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ RUN apt-get update && \ WORKDIR /opt/openbmclapi COPY package-lock.json package.json ./ -RUN npm ci --prod +RUN npm ci --omit=dev COPY --from=install /opt/openbmclapi/dist ./dist COPY nginx/ /opt/openbmclapi/nginx diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 581cdef..071d425 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -3,6 +3,7 @@ events { worker_connections 10240; accept_mutex on; } +user <%= user %>; pid <%= root %>/nginx.pid; worker_rlimit_nofile 65535; http { @@ -57,7 +58,7 @@ http { } location / { - proxy_pass http://unix:<%= root %>/cache/openbmclapi.sock; + proxy_pass http://unix:<%= sock %>; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; @@ -66,7 +67,7 @@ http { location = /auth { internal; - proxy_pass http://unix:<%= root %>/cache/openbmclapi.sock; + proxy_pass http://unix:<%= sock %>; proxy_pass_request_body off; proxy_set_header Content-Length ""; proxy_set_header X-Original-URI $request_uri; diff --git a/src/cluster.ts b/src/cluster.ts index 2511abf..b73fa1a 100644 --- a/src/cluster.ts +++ b/src/cluster.ts @@ -6,7 +6,7 @@ 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 {mkdtemp, open, readdir, readFile, rm, stat, unlink} from 'fs/promises' import got, {type Got, HTTPError} from 'got' import {createServer, Server} from 'http' import {createSecureServer} from 'http2' @@ -14,6 +14,7 @@ import http2Express from 'http2-express-bridge' import {clone, min, sum, template} from 'lodash-es' import morgan from 'morgan' import ms from 'ms' +import {userInfo} from 'node:os' import {tmpdir} from 'os' import pMap from 'p-map' import {basename, dirname, join, sep} from 'path' @@ -234,7 +235,7 @@ export class Cluster { } public async setupNginx(pwd: string, appPort: number, proto: string): Promise { - this._port = join(this.cacheDir, 'openbmclapi.sock') + this._port = '/tmp/openbmclapi.sock' await rm(this._port, {force: true}) const dir = await mkdtemp(join(tmpdir(), 'openbmclapi')) const confFile = `${dir}/nginx/nginx.conf` @@ -247,6 +248,8 @@ export class Cluster { root: pwd, port: appPort, ssl: proto === 'https', + sock: this._port, + user: userInfo().username, })) const logFile = join(__dirname, '..', 'access.log') @@ -288,10 +291,6 @@ export class Cluster { } this.server.listen(this._port, resolve) }) - if (typeof this._port === 'string') { - // eslint-disable-next-line @typescript-eslint/no-magic-numbers - await chmod(this._port, 0o777) - } } public async connect(): Promise {