Skip to content

Commit

Permalink
Merge 5517060 into f722fe8
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch authored Feb 24, 2021
2 parents f722fe8 + 5517060 commit 9cacbe8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
6 changes: 2 additions & 4 deletions src/receivers/ExpressReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { InstallProvider, CallbackOptions, InstallProviderOptions, InstallURLOpt
import App from '../App';
import { ReceiverAuthenticityError, ReceiverMultipleAckError, ReceiverInconsistentStateError } from '../errors';
import { AnyMiddlewareArgs, Receiver, ReceiverEvent } from '../types';
import { renderHtmlForInstallPath } from './render-html-for-install-path';

// TODO: we throw away the key names for endpoints, so maybe we should use this interface. is it better for migrations?
// if that's the reason, let's document that with a comment.
Expand Down Expand Up @@ -145,10 +146,7 @@ export default class ExpressReceiver implements Receiver {
scopes: scopes!,
userScopes: installerOptions.userScopes,
});
res.send(`<a href=${url}><img alt=""Add to Slack"" height="40" width="139"
src="https://platform.slack-edge.com/img/add_to_slack.png"
srcset="https://platform.slack-edge.com/img/add_to_slack.png 1x,
https://platform.slack-edge.com/img/add_to_slack@2x.png 2x" /></a>`);
res.send(renderHtmlForInstallPath(url));
} catch (error) {
next(error);
}
Expand Down
19 changes: 2 additions & 17 deletions src/receivers/HTTPReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { InstallProvider, CallbackOptions, InstallProviderOptions, InstallURLOpt
import { verify as verifySlackAuthenticity, BufferedIncomingMessage } from './verify-request';
import App from '../App';
import { Receiver, ReceiverEvent } from '../types';
import { renderHtmlForInstallPath } from './render-html-for-install-path';
import {
ReceiverMultipleAckError,
ReceiverInconsistentStateError,
Expand Down Expand Up @@ -388,7 +389,7 @@ export default class HTTPReceiver implements Receiver {
const url = await installer.generateInstallUrl(installUrlOptions);

// Generate HTML response body
const body = htmlForInstallPath(url);
const body = renderHtmlForInstallPath(url);

// Serve a basic HTML page including the "Add to Slack" button.
// Regarding headers:
Expand Down Expand Up @@ -433,22 +434,6 @@ function parseBody(req: BufferedIncomingMessage) {
return JSON.parse(bodyAsString);
}

function htmlForInstallPath(addToSlackUrl: string) {
return `<html>
<body>
<a href=${addToSlackUrl}>
<img
alt="Add to Slack"
height="40"
width="139"
src="https://platform.slack-edge.com/img/add_to_slack.png"
srcset="https://platform.slack-edge.com/img/add_to_slack.png 1x, https://platform.slack-edge.com/img/add_to_slack@2x.png 2x"
/>
</a>
</body>
</html>`;
}

// Option keys for tls.createServer() and tls.createSecureContext(), exclusive of those for http.createServer()
const httpsOptionKeys = [
'ALPNProtocols',
Expand Down
6 changes: 2 additions & 4 deletions src/receivers/SocketModeReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { InstallProvider, CallbackOptions, InstallProviderOptions, InstallURLOpt
import { WebAPICallResult } from '@slack/web-api';
import App from '../App';
import { Receiver, ReceiverEvent } from '../types';
import { renderHtmlForInstallPath } from './render-html-for-install-path';

// TODO: we throw away the key names for endpoints, so maybe we should use this interface. is it better for migrations?
// if that's the reason, let's document that with a comment.
Expand Down Expand Up @@ -113,10 +114,7 @@ export default class SocketModeReceiver implements Receiver {
userScopes: installerOptions.userScopes,
});
res.writeHead(200, {});
res.end(`<html><body><a href=${url}><img alt=""Add to Slack"" height="40" width="139"
src="https://platform.slack-edge.com/img/add_to_slack.png"
srcset="https://platform.slack-edge.com/img/add_to_slack.png 1x,
https://platform.slack-edge.com/img/add_to_slack@2x.png 2x" /></a></body></html>`);
res.end(renderHtmlForInstallPath(url));
} catch (err) {
throw new Error(err);
}
Expand Down
15 changes: 15 additions & 0 deletions src/receivers/render-html-for-install-path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export function renderHtmlForInstallPath(addToSlackUrl: string) {
return `<html>
<body>
<a href=${addToSlackUrl}>
<img
alt="Add to Slack"
height="40"
width="139"
src="https://platform.slack-edge.com/img/add_to_slack.png"
srcset="https://platform.slack-edge.com/img/add_to_slack.png 1x, https://platform.slack-edge.com/img/add_to_slack@2x.png 2x"
/>
</a>
</body>
</html>`;
}

0 comments on commit 9cacbe8

Please sign in to comment.