Skip to content

Commit

Permalink
add proper support for relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
rauchg committed Nov 19, 2015
1 parent a4f3b7e commit 761445f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions bin/slackin
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ program
.option('-c, --channels [<chan>]', 'One or more comma-separated channel names to allow single-channel guests [$SLACK_CHANNELS]', process.env.SLACK_CHANNELS)
.option('-c, --channel <chan>', 'Single channel guest invite (deprecated) [$SLACK_CHANNEL]', process.env.SLACK_CHANNEL)
.option('-i, --interval <int>', 'How frequently (ms) to poll Slack [$SLACK_INTERVAL or 5000]', process.env.SLACK_INTERVAL || 5000)
.option('-P, --path', 'Path to serve slackin under', '/')
.option('-s, --silent', 'Do not print out warns or errors')
.option('-c, --css <file>', 'Full URL to a custom CSS file to use on the main page')
.parse(process.argv);
Expand Down
4 changes: 2 additions & 2 deletions lib/assets/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ body.addEventListener('submit', function(ev){

function invite(channel, email, fn){
request
.post('invite')
.post(data.path + 'invite')
.send({
channel: channel,
email: email
Expand All @@ -52,7 +52,7 @@ function invite(channel, email, fn){
var url = document.createElement('a');
url.href = window.location;
// realtime updates
var socket = io({path: (url.pathname + '/socket.io').replace('//','/')});
var socket = io({ path: data.path + 'socket.io' });
socket.on('data', function(users){
for (var i in users) update(i, users[i]);
});
Expand Down
2 changes: 1 addition & 1 deletion lib/assets/iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
// use dom element for better cross browser compatibility
var url = document.createElement('a');
url.href = window.location;
var socket = io({path: (url.pathname.replace(/\/iframe$/, '') + '/socket.io').replace('//','/')});
var socket = io({ path: data.path + 'socket.io' });
var count = document.getElementsByClassName('slack-count')[0];

socket.on('data', function(users){
Expand Down
3 changes: 2 additions & 1 deletion lib/iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const logo = read(__dirname + '/assets/slack.svg').toString('base64');
const js = read(__dirname + '/assets/iframe.js').toString();
const css = read(__dirname + '/assets/iframe-button.css').toString();

export default function button({ active, total, large }){
export default function iframe({ path, active, total, large }){
let str = '';
if (active) str = `${active}/`;
if (total) str += total;
Expand All @@ -25,6 +25,7 @@ export default function button({ active, total, large }){
}),
dom('script', `
data = {};
data.path = ${JSON.stringify(path)};
data.total = ${total != null ? total : 'null'};
data.active = ${active != null ? active : 'null'};
`),
Expand Down
5 changes: 3 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default function slackin({
interval = 5000, // jshint ignore:line
org,
css,
path='/',
channels,
silent = false // jshint ignore:line
}){
Expand Down Expand Up @@ -70,7 +71,7 @@ export default function slackin({
dom('link rel="shortcut icon" href=https://slack.global.ssl.fastly.net/272a/img/icons/favicon-32.png'),
css && dom('link rel=stylesheet', { href: css })
),
splash({ css, name, org, logo, channels, active, total })
splash({ path, css, name, org, logo, channels, active, total })
);
res.type('html');
res.send(page.toHTML());
Expand Down Expand Up @@ -129,7 +130,7 @@ export default function slackin({
let large = 'large' in req.query;
let { active, total } = slack.users;
res.type('html');
res.send(iframe({ active, total, large }).toHTML());
res.send(iframe({ path, active, total, large }).toHTML());
});

app.get('/iframe/dialog', (req, res) => {
Expand Down
10 changes: 7 additions & 3 deletions lib/splash.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import dom from 'vd';

export default function splash({ name, org, logo, active, total, channels, iframe }){
export default function splash({ path, name, org, logo, active, total, channels, iframe }){
let div = dom('.splash',
!iframe && dom('.logos',
logo && dom('.logo.org'),
Expand Down Expand Up @@ -43,9 +43,13 @@ export default function splash({ name, org, logo, active, total, channels, ifram
),
style({ logo, active, iframe }),
// xxx: single build
dom('script', `
data = {};
data.path = ${JSON.stringify(path)};
`),
dom('script src=https://cdn.socket.io/socket.io-1.3.2.js'),
dom('script src=assets/superagent.js'),
dom('script src=assets/client.js')
dom(`script src=${path}assets/superagent.js`),
dom(`script src=${path}assets/client.js`)
);
return div;
}
Expand Down

0 comments on commit 761445f

Please sign in to comment.