Browse Source

fix: update Jupiter price API endpoint and add Dockerfile

- Replace deprecated price.jup.ag/v4 with api.jup.ag/price/v2
- Add multi-stage Dockerfile for containerized deployment
lushdog@outlook.com 1 tháng trước cách đây
mục cha
commit
02777b36ef
3 tập tin đã thay đổi với 38 bổ sung3 xóa
  1. 34 0
      Dockerfile
  2. 3 2
      src/services/jupiter.js
  3. 1 1
      test-tx-analysis.js

+ 34 - 0
Dockerfile

@@ -0,0 +1,34 @@
+# 构建阶段
+FROM node:20-alpine AS builder
+# 设置工作目录
+WORKDIR /app
+# 复制 package.json 和 pnpm-lock.yaml(如果有的话)
+COPY package.json pnpm-lock.yaml* ./
+# 安装 pnpm
+RUN npm install -g pnpm
+# 安装依赖
+RUN pnpm install --frozen-lockfile
+# 生产阶段
+FROM node:20-alpine AS production
+# 安装必要的系统依赖
+RUN apk add --no-cache dumb-init
+# 创建非 root 用户
+RUN addgroup -g 1001 -S nodejs && \
+    adduser -S nodejs -u 1001
+# 设置工作目录
+WORKDIR /app
+# 从构建阶段复制依赖
+COPY --from=builder /app/node_modules ./node_modules
+# 复制应用代码
+COPY --chown=nodejs:nodejs . .
+# 切换到非 root 用户
+USER nodejs
+# 暴露端口(如果有需要)
+# EXPOSE 3000
+# 使用 dumb-init 处理信号
+ENTRYPOINT ["dumb-init", "--"]
+# 启动应用
+CMD ["node", "index.js"]
+# 健康检查
+HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
+    CMD node -e "console.log('healthy')" || exit 1

+ 3 - 2
src/services/jupiter.js

@@ -62,8 +62,9 @@ export class JupiterSwapper {
 
   async getTokenPrices(tokenAddresses) {
     try {
-      const mints = tokenAddresses.join(',');
-      const response = await axios.get(`https://price.jup.ag/v4/price?ids=${mints}`, {
+      const ids = tokenAddresses.join(',');
+      const response = await axios.get('https://api.jup.ag/price/v2', {
+        params: { ids },
         timeout: 10000,
       });
       return response.data.data || {};

+ 1 - 1
test-tx-analysis.js

@@ -107,7 +107,7 @@ async function analyzeTransaction() {
     try {
       const axios = (await import('axios')).default;
       const response = await axios.get(
-        `https://price.jup.ag/v4/price?ids=${mints.join(',')}`,
+        `https://api.jup.ag/price/v2?ids=${mints.join(',')}`,
         { timeout: 10000 }
       );