Sfoglia il codice sorgente

Add shared project support

ghorsington 4 anni fa
parent
commit
130fa61fad

+ 4 - 0
docker-compose.dev.yml

@@ -1,6 +1,10 @@
 version: '3.7'
 
 services:
+  noctbot:
+    ports:
+      - 8181:8181
+
   db:
     ports:
       - 5432:5432

+ 2 - 0
web/package.json

@@ -31,6 +31,7 @@
 		"compression": "^1.7.4",
 		"dotenv": "^8.2.0",
 		"express": "^4.17.1",
+		"make-error": "^1.3.6",
 		"node-fetch": "^2.6.0",
 		"rpc_ts": "^2.1.0",
 		"sirv": "^1.0.5"
@@ -41,6 +42,7 @@
 		"@babel/plugin-transform-runtime": "^7.11.0",
 		"@babel/preset-env": "^7.11.0",
 		"@babel/runtime": "^7.11.2",
+		"@rollup/plugin-alias": "^3.1.1",
 		"@rollup/plugin-babel": "^5.1.0",
 		"@rollup/plugin-commonjs": "^14.0.0",
 		"@rollup/plugin-json": "^4.1.0",

+ 6 - 0
web/rollup.config.js

@@ -7,6 +7,7 @@ import svelte from "rollup-plugin-svelte";
 import babel from "@rollup/plugin-babel";
 import { terser } from "rollup-plugin-terser";
 import config from "sapper/config/rollup";
+import alias from "@rollup/plugin-alias";
 import pkg from "./package.json";
 
 const preprocess = [
@@ -93,6 +94,11 @@ export default {
             resolve({
                 dedupe: ["svelte"],
             }),
+            alias({
+                entries: [
+                    { find: "@shared", replacement: "../../shared/lib/src" },
+                ],
+            }),
             commonjs(),
             typescript(),
             json(),

+ 1 - 0
web/src/environment.ts

@@ -9,6 +9,7 @@ if (process.env.NODE_ENV === "development") {
     });
 
     process.env.TYPEORM_HOST = "localhost";
+    process.env.NOCTBOT_ADDR = "localhost";
     process.env.TYPEORM_USERNAME = process.env.DB_USERNAME;
     process.env.TYPEORM_PASSWORD = process.env.DB_PASSWORD;
     process.env.TYPEORM_DATABASE = process.env.DB_NAME;

+ 3 - 1
web/src/routes/auth.ts

@@ -1,6 +1,8 @@
 import { Request as ExpressRequest, Response as ExpressResponse } from "express";
+import { rpcClient } from "src/rpc";
 
 export const get = async (req: ExpressRequest, res: ExpressResponse): Promise<void> => {
-    console.log(req.url);
+    const result = await rpcClient.getPing({ ping: "PING" });
+    console.log(`Res: ${result.text}, url: ${req.url}`);
     res.redirect("/");
 };

+ 1 - 1
web/src/rpc.ts

@@ -3,6 +3,6 @@ import { NoctBotService } from "@shared/rpc/backend";
 import { NodeHttpTransport } from "@improbable-eng/grpc-web-node-http-transport";
 
 export const rpcClient = ModuleRpcProtocolClient.getRpcClient(NoctBotService, {
-    remoteAddress: `http://noctbot:${process.env.WEB_PORT}`,
+    remoteAddress: `http://${process.env.NOCTBOT_ADDR}:${process.env.WEB_PORT}`,
     getGrpcWebTransport: NodeHttpTransport(),
 });

+ 0 - 5
web/tsconfig.json

@@ -23,9 +23,4 @@
     "exclude": [
         "node_modules"
     ],
-    "references": [
-        {
-            "path": "../shared"
-        }
-    ]
 }