-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
64 lines (55 loc) · 1.72 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const express = require('express');
const app = express();
const fs = require('fs');
app.listen(process.env.PORT || 6999);
console.log('Server is running on port 6999');
app.get('/', (req, res) => {
res.send('Hello World!');
});
let jsFile = null;
let cssFile = null;
const readFilePromise = (filePath) => {
return new Promise((resolve, reject) => {
fs.readFile(filePath, 'utf-8', (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}
const readDirPromise = (dirPath) => {
return new Promise((resolve, reject) => {
fs.readdir(dirPath, (err, files) => {
if (err) {
reject(err);
} else {
resolve(files);
}
});
});
}
app.get('/test.js', async (req, res) => {
let files = await readDirPromise(__dirname + '/sdk/dist/assets');
files.forEach(file => {
if (file.includes('js')) {
jsFile = file;
}
else if (file.includes('css')) {
cssFile = file;
}
});
let file = await readFilePromise(__dirname + `/sdk/dist/assets/${jsFile}`);
file += `
const styleSheetLink = document.createElement('link');
styleSheetLink.rel = 'stylesheet';
styleSheetLink.href = 'https://aqueous-anchorage-20803.herokuapp.com/index.css';
document.head.appendChild(styleSheetLink);
`;
const finalFile = file.replaceAll("STRING_PORTAL_SERVER", process.env.PORTAL_SERVER);
res.send(finalFile);
});
app.get('/index.css', (req, res) => {
res.sendFile(__dirname + `/sdk/dist/assets/${cssFile}`);
})