Sfoglia il codice sorgente

bugfix to render ejs

Yuki Takei 4 anni fa
parent
commit
b13eaaae38

+ 2 - 0
packages/slackbot-proxy/package.json

@@ -38,6 +38,7 @@
     "compression": "^1.7.4",
     "cookie-parser": "^1.4.5",
     "date-fns": "^2.23.0",
+    "ejs": "^3.1.6",
     "express-bunyan-logger": "^1.3.3",
     "extensible-custom-error": "^0.0.7",
     "helmet": "^4.6.0",
@@ -52,6 +53,7 @@
     "@tsed/exceptions": "^6.43.0",
     "@tsed/json-mapper": "^6.43.0",
     "@tsed/schema": "^6.43.0",
+    "@types/ejs": "^3.0.7",
     "bootstrap": "^5.0.2",
     "browser-bunyan": "^1.6.3",
     "morgan": "^1.10.0",

+ 12 - 7
packages/slackbot-proxy/src/controllers/slack.ts

@@ -1,8 +1,10 @@
 import {
-  BodyParams, Controller, Get, Inject, PlatformResponse, Post, Req, Res, UseBefore,
+  BodyParams, Constant, Controller, Get, Inject, PlatformResponse, Post, Req, Res, UseBefore,
 } from '@tsed/common';
 
+import path from 'path';
 import axios from 'axios';
+import ejs from 'ejs';
 
 import { WebAPICallResult } from '@slack/web-api';
 
@@ -35,6 +37,9 @@ const logger = loggerFactory('slackbot-proxy:controllers:slack');
 @Controller('/slack')
 export class SlackCtrl {
 
+  @Constant('views.root')
+  readonly viewsRoot: string;
+
   @Inject()
   installerService: InstallerService;
 
@@ -353,16 +358,16 @@ export class SlackCtrl {
 
         // check whether bot is not null
         if (installation.bot == null) {
-          const result = await platformRes.render('install-succeeded-but-has-problem.ejs', { reason: '`installation.bot` is null' });
+          const html = await ejs.renderFile(path.join(this.viewsRoot, 'install-succeeded-but-has-problem.ejs'), { reason: '`installation.bot` is null' });
           res.writeHead(500, { 'Content-Type': 'text/html; charset=utf-8' });
-          return res.end(result);
+          return res.end(html);
         }
 
         // render success page
         const appPageUrl = `https://slack.com/apps/${installation.appId}`;
-        const result = await platformRes.render('install-succeeded.ejs', { appPageUrl });
+        const html = await ejs.renderFile(path.join(this.viewsRoot, 'install-succeeded.ejs'), { appPageUrl });
         res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
-        res.end(result);
+        res.end(html);
 
         // generate client
         const client = generateWebClient(installation.bot.token);
@@ -377,10 +382,10 @@ export class SlackCtrl {
         ]);
       },
       failure: async(error, installOptions, req, res) => {
-        const result = await platformRes.status(500).render('install-failed.ejs', { url: addToSlackUrl });
+        const html = await ejs.renderFile(path.join(this.viewsRoot, 'install-failed.ejs'), { url: addToSlackUrl });
 
         res.writeHead(500, { 'Content-Type': 'text/html; charset=utf-8' });
-        res.end(result);
+        res.end(html);
       },
     });
   }

+ 6 - 1
yarn.lock

@@ -2661,6 +2661,11 @@
   resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.5.tgz#b14efa8852b7768d898906613c23f688713e02cd"
   integrity sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ==
 
+"@types/ejs@^3.0.7":
+  version "3.0.7"
+  resolved "https://registry.yarnpkg.com/@types/ejs/-/ejs-3.0.7.tgz#4f2af032f65c54e2bc0b32abce0125af7923b143"
+  integrity sha512-AUxAGNIPr7wQmzdFMNhHy/RkR5kk8gSzAZIuCYY//6ZYJKHvnjezmoEYP34coPleUPnqrUWt03cCq7NzNaA/qg==
+
 "@types/express-serve-static-core@^4.17.18":
   version "4.17.19"
   resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.19.tgz#00acfc1632e729acac4f1530e9e16f6dd1508a1d"
@@ -7029,7 +7034,7 @@ ejs@^2.6.1:
   version "2.6.1"
   resolved "https://registry.yarnpkg.com/ejs/-/ejs-2.6.1.tgz#498ec0d495655abc6f23cd61868d926464071aa0"
 
-ejs@^3.1.5:
+ejs@^3.1.5, ejs@^3.1.6:
   version "3.1.6"
   resolved "https://registry.yarnpkg.com/ejs/-/ejs-3.1.6.tgz#5bfd0a0689743bb5268b3550cceeebbc1702822a"
   integrity sha512-9lt9Zse4hPucPkoP7FHDF0LQAlGyF9JVpnClFLFH3aSSbxmyoqINRpp/9wePWJTUl4KOQwRL72Iw3InHPDkoGw==