feat: add proxy for docker

This commit is contained in:
yidadaa 2023-04-09 20:35:42 +08:00
parent c8be5e4267
commit 1bb7b4a653
2 changed files with 21 additions and 12 deletions

View File

@ -3,12 +3,12 @@ FROM node:18-alpine AS base
FROM base AS deps FROM base AS deps
RUN apk add --no-cache libc6-compat RUN apk add --no-cache libc6-compat
RUN apk --no-cache add proxychains-ng
WORKDIR /app WORKDIR /app
COPY package.json yarn.lock ./ COPY package.json yarn.lock ./
RUN yarn config set registry 'https://registry.npm.taobao.org'
RUN yarn install RUN yarn install
FROM base AS builder FROM base AS builder
@ -28,6 +28,8 @@ RUN yarn build
FROM base AS runner FROM base AS runner
WORKDIR /app WORKDIR /app
RUN apk add proxychains-ng
ENV PROXY_URL="" ENV PROXY_URL=""
ENV OPENAI_API_KEY="" ENV OPENAI_API_KEY=""
ENV CODE="" ENV CODE=""
@ -43,8 +45,16 @@ CMD if [ -n "$PROXY_URL" ]; then \
protocol=$(echo $PROXY_URL | cut -d: -f1); \ protocol=$(echo $PROXY_URL | cut -d: -f1); \
host=$(echo $PROXY_URL | cut -d/ -f3 | cut -d: -f1); \ host=$(echo $PROXY_URL | cut -d/ -f3 | cut -d: -f1); \
port=$(echo $PROXY_URL | cut -d: -f3); \ port=$(echo $PROXY_URL | cut -d: -f3); \
echo "$protocol $host $port" >> /etc/proxychains.conf; \ conf=/etc/proxychains.conf; \
proxychains node server.js; \ echo "strict_chain" >> $conf; \
echo "proxy_dns" >> $conf; \
echo "remote_dns_subnet 224" >> $conf; \
echo "tcp_read_time_out 15000" >> $conf; \
echo "tcp_connect_time_out 8000" >> $conf; \
echo "[ProxyList]" >> $conf; \
echo "$protocol $host $port" >> $conf; \
cat /etc/proxychains.conf; \
proxychains -f $conf node server.js; \
else \ else \
node server.js; \ node server.js; \
fi fi

View File

@ -1,14 +1,13 @@
import fetch from "node-fetch"; import fetch from "node-fetch";
import fs from "fs/promises"; import fs from "fs/promises";
const RAW_CN_URL = const RAW_FILE_URL = "https://raw.githubusercontent.com/";
"https://raw.githubusercontent.com/PlexPt/awesome-chatgpt-prompts-zh/main/prompts-zh.json"; const MIRRORF_FILE_URL = "https://raw.fgit.ml/";
const CN_URL =
"https://cdn.jsdelivr.net/gh/PlexPt/awesome-chatgpt-prompts-zh@main/prompts-zh.json"; const RAW_CN_URL = "PlexPt/awesome-chatgpt-prompts-zh/main/prompts-zh.json";
const RAW_EN_URL = const CN_URL = MIRRORF_FILE_URL + RAW_CN_URL;
"https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv"; const RAW_EN_URL = "f/awesome-chatgpt-prompts/main/prompts.csv";
const EN_URL = const EN_URL = MIRRORF_FILE_URL + RAW_EN_URL;
"https://cdn.jsdelivr.net/gh/f/awesome-chatgpt-prompts@main/prompts.csv";
const FILE = "./public/prompts.json"; const FILE = "./public/prompts.json";
async function fetchCN() { async function fetchCN() {