Quellcode durchsuchen

fix build issue

czhen vor 3 Jahren
Ursprung
Commit
41abd0a130
3 geänderte Dateien mit 20 neuen und 8 gelöschten Zeilen
  1. 7 5
      Dockerfile
  2. 3 2
      express/package.json
  3. 10 1
      express/src/app.ts

+ 7 - 5
Dockerfile

@@ -8,7 +8,7 @@ WORKDIR /app/client
 RUN yarn install
 RUN yarn build
 # # => Building Server
-WORKDIR /app/server
+WORKDIR /app/express
 RUN yarn install
 ENV NODE_ENV production
 ENV PORT 80
@@ -17,11 +17,11 @@ RUN yarn build
 # => Copy to Final container
 FROM mhart/alpine-node:14
 WORKDIR /app
-COPY --from=builder /app/server/dist /app/dist
-COPY --from=builder /app/server/build /app/build
+COPY --from=builder /app/express/dist /app/dist
+COPY --from=builder /app/client/build /app/build
 # COPY --from=builder /app/server/node_modules /app/node_modules
-COPY --from=builder /app/server/package.json /app/package.json
-COPY --from=builder /app/server/yarn.lock /app/yarn.lock
+COPY --from=builder /app/express/package.json /app/package.json
+COPY --from=builder /app/express/yarn.lock /app/yarn.lock
 
 # => Reinstall production dependencies and clean cache
 RUN yarn install --production && yarn cache clean
@@ -35,5 +35,7 @@ RUN chmod +x /app/build/env.sh
 RUN chgrp -R 0 /app && \
     chmod -R g=u /app
 
+EXPOSE 3000
+
 # RUN echo -e window.__version="{\"version\":\""$VERSION"\"}" > /app/build/version.js
 CMD [ "/bin/bash", "-c", "/app/build/env.sh && yarn start:prod" ]

+ 3 - 2
express/package.json

@@ -30,8 +30,9 @@
     "build": "yarn clean && tsc",
     "prestart": "yarn build",
     "start": "node .",
+    "start:plugin": "yarn build && cross-env PLUGIN_DEV=1 node dist/milvus-insight/express/src/app.js",
+    "start:prod": "node dist/app.js",
     "test": "echo \"Error: no test specified\" && exit 1",
-    "clean": "rimraf dist",
-    "start:plugin": "yarn build && cross-env PLUGIN_DEV=1 node dist/milvus-insight/express/src/app.js"
+    "clean": "rimraf dist"
   }
 }

+ 10 - 1
express/src/app.ts

@@ -1,4 +1,4 @@
-import express  from "express";
+import express from "express";
 import cors from "cors";
 import helmet from "helmet";
 import * as http from "http";
@@ -15,6 +15,7 @@ import {
   ErrorInterceptor,
 } from "./interceptors";
 import { getDirectories, generateCfgs } from "./utils";
+import * as path from "path";
 
 const PLUGIN_DEV = process.env?.PLUGIN_DEV;
 const SRC_PLUGIN_DIR = "src/plugins";
@@ -108,6 +109,14 @@ getDirectories(SRC_PLUGIN_DIR, async (dirErr: Error, dirRes: [string]) => {
   app.use("/api/v1", router);
   app.use("/api/plugins", pluginsRouter);
 
+  // Return client build files
+  app.use(express.static("build"));
+  // handle every other route with index.html, which will contain
+  // a script tag to your application's JavaScript file(s).
+  app.get("*", (request, response) => {
+    response.sendFile(path.join(__dirname, "../build/index.html"));
+  });
+
   // ErrorInterceptor
   app.use(ErrorInterceptor);
   // start server