Skip to content

Commit d42cdbc

Browse files
committed
feat: support etherpad hosted at subpath
1 parent 001dd23 commit d42cdbc

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,26 @@ exports.connect = (host) => {
1616
// If host is undefined set to local host
1717
if (!host) {
1818
padState.host = 'http://127.0.0.1:9001';
19+
padState.path = '';
1920
padState.padId = randomString();
2021
} else {
2122
const parsed = new URL(host);
2223
padState.host = `${parsed.protocol}//${parsed.host}`;
23-
padState.padId = parsed.pathname.replace('/p/', '');
24+
const padIdParam = '/p/';
25+
const indexOfPadId = parsed.pathname.indexOf(padIdParam);
26+
if (indexOfPadId >= 0) {
27+
padState.path = parsed.pathname.substring(0, indexOfPadId)
28+
padState.padId = parsed.pathname.substring(indexOfPadId + padIdParam.length)
29+
} else {
30+
padState.path = '';
31+
padState.padId = randomString();
32+
}
2433
}
2534

2635
// Connect to Socket
27-
superagent.get(`${padState.host}/p/${padState.padId}`).then((d) => {
36+
superagent.get(`${padState.host}${padState.path}/p/${padState.padId}`).then((d) => {
2837
const socket = require('socket.io-client')(padState.host, {
38+
'path': `${padState.path}/socket.io`,
2939
'query': `padId=${padState.padId}`,
3040
'forceNew': true,
3141
'timeout': 1000,

0 commit comments

Comments
 (0)