Coder Social home page Coder Social logo

wictorwilen / express-msteams-host Goto Github PK

View Code? Open in Web Editor NEW
12.0 12.0 6.0 1.24 MB

Express utility for Microsoft Teams solutions

License: MIT License

TypeScript 97.93% JavaScript 2.07%
decorators express express-router expressjs hacktoberfest microsoft-teams microsoftteams nodejs typescript

express-msteams-host's Introduction

Hi and welcome!

Wictor Wilen works as Principal PM Manager in the Microsoft People System team, creating highly personalized experiences that adapt to the unique interests of our users and the relationships that they have with other people and their content. Formerly member of the Microsoft Regional Director network and a SharePoint MVP for twelve years, as well as an author and a well known international speaker.

  • ๐Ÿ’ฌ Ask me about anything related to people and profiles for the Microsoft 365 platform.
  • ๐Ÿ”ญ Iโ€™m the founder of the successful (but now retired) open-source project Microsoft Teams Yeoman Generator - Yo Teams
  • โ˜‘๏ธ Creator of the free online RACI editor tool - raci.app
  • โฌ‡๏ธ I have over a million downloads (1,021,164 as of March 2024) of my various npm packages
  • ๐Ÿ“ซ You can always reach me on Twitter or Mastodon (@wictor | @[email protected]) or read more about me on www.wictorwilen.se
  • ๐Ÿ’ป I have a fascination for IoT and especially building my own stuff (hardware & software)
  • โšก Fun fact about me is that I sold my first software at age 14 built with Turbo Pascal, a school scheduling management system that set the foundation for future commercial software in this space.

express-msteams-host's People

Contributors

felipeplets avatar laurencemommers avatar mtcmarkfranco avatar wictorwilen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

express-msteams-host's Issues

Possibility to host a Teams App in a website subdirectory

Introduction

I'm having some trouble hosting Teams Apps in IIS, generated by your Yeoman generator for Microsoft Teams, using:

yo teams

Then i did a build, with:

gulp ngrok-serve

I am able to host the "dist" directory in IIS, after:

  • installing IISNode
  • installing UrlRewrite
  • and adding the following web.config file to the "dist" directory:
    <configuration>
        <system.webServer>

            <!-- indicates that the server.js file is a node.js application
            to be handled by the iisnode module -->

            <handlers>
                <add name="iisnode" path="server.js" verb="*" modules="iisnode" />
            </handlers>

            <rewrite>
                <rules>
                    <rule name="sendToNode">
                        <match url="/*" />
                        <action type="Rewrite" url="server.js" />
                    </rule>
                </rules>
            </rewrite>

        </system.webServer>
    </configuration>

This seems to work just fine, when hosting this directory as the root of an IIS Website (its URL "http://localhost" shows the purple teams logo in a browser).

Problem

The problem is that this does not work when hosting this directory as an Application under an existing Website (as a subdirectory). For example if this Application now has the URL "http://localhost/teams", then browsing there results in a blank page with only the text:

Cannot GET /teams

if i go into the generated file "server.ts", and replace the following:

express.use("/", Express.static(path.join(__dirname, "web/"), {
    index: "index.html"
}));

with:

express.use("/teams", Express.static(path.join(__dirname, "web/"), {
    index: "index.html"
}));

and do a build again, then the error goes away and i see the purple teams logo again. But the logo has the wrong size, because "/teams/web/index.html" still contains the old path of the css file:

<link rel="stylesheet" href="/styles/main.css">

instead of a path relative to the current folder, which would work in both cases:

<link rel="stylesheet" href="styles/main.css">

But, i have no idea of all the potential places, where the path would need to be changed.

Question

Is there a single place where i can prefix all paths (with for example "/teams")?

Suggestion

It would be most convenient if the setting could still be change, without doing a build (with "gulp ngrok-serve"). So if you implement this, then i suggest that you get this prefix ("/teams" in the above example), at runtime from the variable "process.env.virtualDirPath" if it is defined.

This way, i can use the web.config file in the "dist" directory as the single place where i can prefix all paths. by adding an appSettings to it:

<configuration>
    <appSettings>
        <add key="virtualDirPath" value="/teams" />
    </appSettings>
    
    <system.webServer>

        <!-- indicates that the server.js file is a node.js application
        to be handled by the iisnode module -->

        <handlers>
            <add name="iisnode" path="server.js" verb="*" modules="iisnode" />
        </handlers>

        <rewrite>
            <rules>
                <rule name="sendToNode">
                    <match url="/*" />
                    <action type="Rewrite" url="server.js" />
                </rule>
            </rules>
        </rewrite>

    </system.webServer>
</configuration>

IISNode then automatically defines process.env.virtualDirPath with value "/teams" (i've tested this). You could for example implement:

const virtualDirPath = process.env.virtualDirPath || "/";

express.use(virtualDirPath, Express.static(path.join(__dirname, "web/"), {
    index: "index.html"
}));

This would also make it practical for an administrator to change the subdirectory in the URL, by only being required to also edit the web.config file, instead of needing all the developer tools and having to do a build.

Background

Hosting several applications, each in their own subdirectory, under the same IIS Website is a common scenario. In my case the Teams App needs to POST JSON content to a third party application under the same website.

If they are in different websites, then one domain would be accessing another domain. This would require me to set CORS (Cross Origin Resource Sharing) permissions. This is not possible in the third party application. And even if it was, i wouldn't want to unnecessarily expose these permissions to the internet, out of security concerns.

How to configure proxy?

Hi,

Can you tell me how can I configure the proxy while using @BotDeclaration?

Any help is appreciated.

Thank You.

Extend CSP according to the latest docs for manifest version >= 1.13

According to the latest docs for manifest starting with version 1.13, it seems that the CSPs require an update to extend the apps to Microsoft 365 / Outlook

I could provide a PR if this is something that would make sense for this lib?

Current CSP

question: subdirectory hosting

@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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.