From ae04c21d2bcb6bec3289b6a2c67e88368f68d5d1 Mon Sep 17 00:00:00 2001 From: Eric Date: Sat, 29 Apr 2023 02:55:48 +0800 Subject: [PATCH] fix bug --- Dockerfile | 10 ++++++---- request/index.ts | 38 +++++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index d0282f8..022c0a6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,12 @@ # ---- Production ---- FROM node:18-alpine AS production WORKDIR /dist -COPY .next . -COPY public . -COPY package*.json . -COPY next.config.js . + +COPY .next ./.next +COPY public ./public +COPY package*.json ./ +COPY next.config.js ./next.config.js +# use npm ci for production RUN npm install --omit=dev # Expose the port the app will run on EXPOSE 3000 diff --git a/request/index.ts b/request/index.ts index 0791a47..c30d4e1 100644 --- a/request/index.ts +++ b/request/index.ts @@ -1,16 +1,20 @@ import { MJMessage } from "midjourney"; -const streamFetch = (url: string, body: string ,loading?: (uri: MJMessage) => void) => { +const streamFetch = ( + url: string, + body: string, + loading?: (uri: MJMessage) => void +) => { return fetch(url, { - method: 'POST', + method: "POST", headers: { - 'Content-type': 'application/json', + "Content-type": "application/json", }, body, - }) .then(async (response) => { + }).then(async (response) => { const reader = response.body?.getReader(); if (reader) { - console.log('Response body is not null'); + // console.log('Response body is not null'); while (true) { const { done, value } = await reader.read(); if (done) { @@ -19,22 +23,22 @@ const streamFetch = (url: string, body: string ,loading?: (uri: MJMessage) => vo //Uint8Array to string const str = new TextDecoder("utf-8").decode(value); console.log(str); - loading &&loading(JSON.parse(str)) + loading && loading(JSON.parse(str)); } } else { - console.log('Response body is null'); + console.log("Response body is null"); } }); -} +}; -export const Imagine = (body: string,loading?: (uri: MJMessage) => void) =>{ - return streamFetch('api/imagine',body,loading) -} +export const Imagine = (body: string, loading?: (uri: MJMessage) => void) => { + return streamFetch("api/imagine", body, loading); +}; -export const Upscale = (body: string,loading?: (uri: MJMessage) => void) =>{ - return streamFetch('api/upscale',body,loading) -} +export const Upscale = (body: string, loading?: (uri: MJMessage) => void) => { + return streamFetch("api/upscale", body, loading); +}; -export const Variation = (body: string,loading?: (uri: MJMessage) => void) =>{ - return streamFetch('api/upscale',body,loading) -} \ No newline at end of file +export const Variation = (body: string, loading?: (uri: MJMessage) => void) => { + return streamFetch("api/upscale", body, loading); +};