feat: 添加环境变量配置支持
添加.env.example文件并更新Dockerfile和index.js以支持通过环境变量配置API基础路径和缓存目录
This commit is contained in:
3
.env.example
Normal file
3
.env.example
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
PORT=9520
|
||||||
|
API_BASE=http://127.0.0.1:9558/api
|
||||||
|
CACHE_DIR=./.cache
|
||||||
@@ -26,6 +26,8 @@ COPY . .
|
|||||||
# 3. 权限与启动
|
# 3. 权限与启动
|
||||||
ENV PORT=9520
|
ENV PORT=9520
|
||||||
ENV CACHE_DIR=/app/.cache
|
ENV CACHE_DIR=/app/.cache
|
||||||
|
ENV API_BASE=http://127.0.0.1:9558/api
|
||||||
|
VOLUME ["/app/.cache"]
|
||||||
|
|
||||||
RUN useradd -m appuser && \
|
RUN useradd -m appuser && \
|
||||||
mkdir -p "$CACHE_DIR" && \
|
mkdir -p "$CACHE_DIR" && \
|
||||||
|
|||||||
4
index.js
4
index.js
@@ -17,8 +17,8 @@ const EventEmitter = require('events');
|
|||||||
|
|
||||||
// Configuration
|
// Configuration
|
||||||
const PORT = process.env.PORT || 9520;
|
const PORT = process.env.PORT || 9520;
|
||||||
const API_BASE = 'http://183.6.121.121:9558/api';
|
const API_BASE = process.env.API_BASE || 'http://127.0.0.1:9558/api';
|
||||||
const CACHE_DIR = path.join(__dirname, '.cache');
|
const CACHE_DIR = process.env.CACHE_DIR ? path.resolve(process.env.CACHE_DIR) : path.join(__dirname, '.cache');
|
||||||
|
|
||||||
// Ensure cache directory exists
|
// Ensure cache directory exists
|
||||||
if (!fs.existsSync(CACHE_DIR)) {
|
if (!fs.existsSync(CACHE_DIR)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user