wictorwilen / express-msteams-host

Express utility for Microsoft Teams solutions
MIT License
13 stars 6 forks source link

question: subdirectory hosting #3

Closed greenpau closed 4 years ago

greenpau commented 4 years ago

@wictorwilen , nice work!

I am hosting yo generated app in a subdirectory, e.g. https://192.168.1.1/myapp/.

I made the following modifications to src/app/server.ts:

diff --git a/src/app/server.ts b/src/app/server.ts
index 5210bb9..3606930 100644
--- a/src/app/server.ts
+++ b/src/app/server.ts
@@ -6,7 +6,7 @@ import { MsTeamsApiRouter, MsTeamsPageRouter } from "express-msteams-host";
 import * as debug from "debug";
 import * as compression from "compression";

-
+const proxyPath = "/myapp";

 // Initialize debug logging module
 const log = debug("msteams");
@@ -44,8 +44,8 @@ express.use(morgan("tiny"));
 express.use(compression());

 // Add /scripts and /assets as static folders
-express.use("/scripts", Express.static(path.join(__dirname, "web/scripts")));
-express.use("/assets", Express.static(path.join(__dirname, "web/assets")));
+express.use(proxyPath + "/scripts", Express.static(path.join(__dirname, "web/scripts")));
+express.use(proxyPath + "/assets", Express.static(path.join(__dirname, "web/assets")));

 // routing for bots, connectors and incoming web hooks - based on the decorators
 // For more information see: https://www.npmjs.com/package/express-msteams-host
@@ -59,7 +59,7 @@ express.use(MsTeamsPageRouter({
 }));

 // Set default web page
-express.use("/", Express.static(path.join(__dirname, "web/"), {
+express.use(proxyPath + "/", Express.static(path.join(__dirname, "web/"), {
     index: "index.html"
 }));

I noticed the following lines in the server.ts:

// routing for bots, connectors and incoming web hooks - based on the decorators
// For more information see: https://www.npmjs.com/package/express-msteams-host
express.use(MsTeamsApiRouter(allComponents));

// routing for pages for tabs and connector configuration
// For more information see: https://www.npmjs.com/package/express-msteams-host
express.use(MsTeamsPageRouter({
    root: path.join(__dirname, "web/"),
    components: allComponents
}));

Do I need to modify MsTeamsApiRouter and MsTeamsPageRouter to account for the subdirectory?

wictorwilen commented 4 years ago

Hi, the MsTeamsApiRouter and MsTeamsPageRouer is both using the decorators to indicate what paths to use. See details in the README.md