javaeeduke commited on
Commit
0b60ed8
·
verified ·
1 Parent(s): 267c51f

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +39 -13
Dockerfile CHANGED
@@ -12,28 +12,54 @@ RUN git clone https://github.com/diegosouzapw/OmniRoute.git .
12
  RUN sed -i '/"sqlite-vec/d' package.json || true
13
  RUN sed -i '/"sqlite-vec-linux-x64/d' package.json || true
14
 
15
- # 3. 【核心修正不破坏原厂 next.config.mjs利用 node 脚本注入允许跨域来源
16
- # 顺便把外传入参数也写进启动脚本,双保险锁死允许域名
17
  RUN node -e " \
18
  const fs = require('fs'); \
19
- let content = fs.readFileSync('next.config.mjs', 'utf8'); \
20
- if (content.includes('nextConfig = {')) { \
21
- content = content.replace('nextConfig = {', \"nextConfig = {\n allowedDevOrigins: ['javaeeduke-om.hf.space', 'localhost:7860'],\"); \
22
- } else if (content.includes('const nextConfig = {')) { \
23
- content = content.replace('const nextConfig = {', \"const nextConfig = {\n allowedDevOrigins: ['javaeeduke-om.hf.space', 'localhost:7860'],\"); \
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  } \
25
- fs.writeFileSync('next.config.mjs', content); \
26
  "
27
 
28
- # 4. 安装全部依赖
29
  RUN npm install --include=dev
30
 
31
- # 锁死端口与环境变量
 
 
 
 
32
  ENV PORT=7860
33
  ENV OMNIROUTE_PORT=7860
34
  ENV HOST=0.0.0.0
35
- ENV NODE_ENV=development
36
  EXPOSE 7860
37
 
38
- # 5. 修改原厂启动命令,让其在运行 run-next.mjs 时也带上官方的名白名单参数
39
- CMD ["node", "scripts/dev/run-next.mjs", "dev", "--allowed-dev-origins", "javaeeduke-om.hf.space"]
 
12
  RUN sed -i '/"sqlite-vec/d' package.json || true
13
  RUN sed -i '/"sqlite-vec-linux-x64/d' package.json || true
14
 
15
+ # 3. 【降维打击编写自动化脚本扫描并把 messages 文件夹下所有 JSON 扁平化带点 Key,
16
+ # 完美重构为带层级对象(正如报错日志里 lodash.set 提示那样)
17
  RUN node -e " \
18
  const fs = require('fs'); \
19
+ const path = require('path'); \
20
+ function unflatten(data) { \
21
+ const result = {}; \
22
+ for (const i in data) { \
23
+ if (i.includes('.')) { \
24
+ const keys = i.split('.'); \
25
+ keys.reduce((r, e, j) => { \
26
+ return r[e] || (r[e] = keys.length - 1 === j ? data[i] : {}); \
27
+ }, result); \
28
+ } else { \
29
+ result[i] = data[i]; \
30
+ } \
31
+ } \
32
+ return result; \
33
+ } \
34
+ const localesDir = path.join(process.cwd(), 'messages'); \
35
+ if (fs.existsSync(localesDir)) { \
36
+ fs.readdirSync(localesDir).forEach(file => { \
37
+ if (file.endsWith('.json')) { \
38
+ const filePath = path.join(localesDir, file); \
39
+ const json = JSON.parse(fs.readFileSync(filePath, 'utf8')); \
40
+ if (json.compliance && json.compliance.eventTypes) { \
41
+ json.compliance.eventTypes = unflatten(json.compliance.eventTypes); \
42
+ } \
43
+ fs.writeFileSync(filePath, JSON.stringify(json, null, 2)); \
44
+ console.log('Successfully patched translation file:', file); \
45
+ } \
46
+ }); \
47
  } \
 
48
  "
49
 
50
+ # 4. 干净安装所有依赖
51
  RUN npm install --include=dev
52
 
53
+ # 5. 执行真正安全的生产构建(此时多语言 Key 已经合规,Next.js 绝不会拒绝打包)
54
+ ENV NEXT_TELEMETRY_DISABLED=1
55
+ RUN npm run build
56
+
57
+ # 锁死端口
58
  ENV PORT=7860
59
  ENV OMNIROUTE_PORT=7860
60
  ENV HOST=0.0.0.0
61
+ ENV NODE_ENV=production
62
  EXPOSE 7860
63
 
64
+ # 6. 用完全没有 webpack-hmr 干扰的生产模式拉起!
65
+ CMD ["npm", "run", "start"]