Skip to content

Commit

Permalink
Support running on Node.js<15
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Zatsarynnyi <[email protected]>
  • Loading branch information
azatsarynnyy committed Nov 1, 2024
1 parent 3b2f137 commit 752c9e7
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions status-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ const ideInfo = require('../product-info.json');
const logsFile = '../std.out';

// watch for the 'joinLink' in the IDE server's output
var joinLink = new Promise((resolve) => {
var joinLink = new Promise((resolve, reject) => {
const watcher = chokidar.watch(logsFile);
watcher.on('change', (event, path) => {
fs.readFile(logsFile, "utf-8", (err, data) => {
if (err)
throw err;
reject(err);

if (data.includes('Join link: tcp://')) {
const tcpLinkRegex = /(tcp:\/\/[^\s]+)/g;
Expand All @@ -45,12 +45,23 @@ app.use(express.static(path.join(__dirname, 'public')));
app.set('view engine', 'ejs');
app.get('/', async function (req, res) {
const ideFullName = ideInfo.productVendor + ' ' + ideInfo.name + ' ' + ideInfo.version;
const invitationLink = (await joinLink).replaceAll('&', '_');

var invitationLink;
try {
// Some user's containers contain Node.js<15
// which doesn't support replaceAll('&', '_')
// So, use replace with regexp here.
invitationLink = (await joinLink).replace(/['&']/g, '_');
} catch (err) {
console.error('Error while getting a join link', err);
}

const dwNamespace = process.env.DEVWORKSPACE_NAMESPACE;
const dwName = process.env.DEVWORKSPACE_NAME;
const title = dwName;
const clusterConsoleURL = process.env.CLUSTER_CONSOLE_URL;
const dashboardURL = process.env.CHE_DASHBOARD_URL;

// render the page from EJS template
res.render('status', { title, ideFullName, dwNamespace, dwName, clusterConsoleURL, invitationLink, dashboardURL });
});
Expand Down

0 comments on commit 752c9e7

Please sign in to comment.