Initial sioconfig migration work
This commit is contained in:
parent
dacda65961
commit
40e2a608f6
8 changed files with 111 additions and 18 deletions
23
src/configuration/ioconfig.js
Normal file
23
src/configuration/ioconfig.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
export default class IOConfiguration {
|
||||
constructor(config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
getSocketURL() {
|
||||
return this.config.urls[0];
|
||||
}
|
||||
}
|
||||
|
||||
IOConfiguration.fromOldConfig = function (oldConfig) {
|
||||
const config = {
|
||||
urls: []
|
||||
};
|
||||
|
||||
['ipv4-ssl', 'ipv4-nossl', 'ipv6-ssl', 'ipv6-nossl'].forEach(key => {
|
||||
if (oldConfig.get('io.' + key)) {
|
||||
config.urls.push(oldConfig.get('io.' + key));
|
||||
}
|
||||
});
|
||||
|
||||
return new IOConfiguration(config);
|
||||
};
|
||||
11
src/io/cluster/nullclusterclient.js
Normal file
11
src/io/cluster/nullclusterclient.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import Promise from 'bluebird';
|
||||
|
||||
export default class NullClusterClient {
|
||||
constructor(ioConfig) {
|
||||
this.ioConfig = ioConfig;
|
||||
}
|
||||
|
||||
getSocketURL(channel) {
|
||||
return Promise.resolve(this.ioConfig.getSocketURL());
|
||||
}
|
||||
}
|
||||
24
src/web/routes/socketconfig.js
Normal file
24
src/web/routes/socketconfig.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import IOConfiguration from '../../configuration/ioconfig';
|
||||
import NullClusterClient from '../../io/cluster/nullclusterclient';
|
||||
import Config from '../../config';
|
||||
import CyTubeUtil from '../../utilities';
|
||||
|
||||
export default function initialize(app) {
|
||||
const ioConfig = IOConfiguration.fromOldConfig(Config);
|
||||
const clusterClient = new NullClusterClient(ioConfig);
|
||||
|
||||
app.get('/socketconfig/:channel.json', (req, res) => {
|
||||
if (!req.params.channel || !CyTubeUtil.isValidChannelName(req.params.channel)) {
|
||||
return res.status(400).json({
|
||||
error: `Channel "${req.params.channel}" does not exist.`
|
||||
});
|
||||
}
|
||||
|
||||
clusterClient.getSocketURL(req.params.channel).then(url => {
|
||||
res.json({
|
||||
url,
|
||||
secure: /^(https|wss)/.test(url)
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -117,7 +117,8 @@ function handleIndex(req, res) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Handles a request for the socket.io information
|
||||
* Legacy socket.io configuration endpoint. This is being migrated to
|
||||
* /socketconfig/<channel name>.json (see ./routes/socketconfig.js)
|
||||
*/
|
||||
function handleSocketConfig(req, res) {
|
||||
if (/\.json$/.test(req.path)) {
|
||||
|
|
@ -243,6 +244,7 @@ module.exports = {
|
|||
app.get("/r/:channel", handleChannel);
|
||||
app.get("/", handleIndex);
|
||||
app.get("/sioconfig(.json)?", handleSocketConfig);
|
||||
require("./routes/socketconfig")(app);
|
||||
app.get("/useragreement", handleUserAgreement);
|
||||
app.get("/contact", handleContactPage);
|
||||
require("./auth").init(app);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue