mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-22 15:24:55 +00:00
[skip-ci] fix static js file fetch
This commit is contained in:
parent
0ddcc01dff
commit
ae409b0044
@ -22,27 +22,6 @@ const path = require('path');
|
||||
const app = express();
|
||||
const compression = require('compression');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
let chunkFile, mainChunkFile;
|
||||
const directory = path.join(__dirname, 'build', 'static', 'js');
|
||||
fs.readdir(directory, function(err, files) {
|
||||
const chunkRegex = /3\.(.+)\.chunk\.(js)$/;
|
||||
const mainChunkRegex = /main\.(.+)\.chunk\.(js)$/;
|
||||
if (err) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Error: Unable to scan directory: ', err);
|
||||
}
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
if (chunkRegex.test(files[i])) {
|
||||
chunkFile = files[i];
|
||||
}
|
||||
if (mainChunkRegex.test(files[i])) {
|
||||
mainChunkFile = files[i];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
app.use(compression());
|
||||
|
||||
app.use(async function(req, res, next) {
|
||||
@ -90,26 +69,33 @@ app.get(['/env.js', '/accounts/env.js'], function(req, res) {
|
||||
app.use(express.static(path.join(__dirname, 'build')));
|
||||
app.use('/accounts', express.static(path.join(__dirname, 'build')));
|
||||
|
||||
app.use(/^\/dashboard\/static\/js\/3\.(.+)\.chunk\.js$/, function(
|
||||
req,
|
||||
res,
|
||||
next
|
||||
) {
|
||||
if (chunkFile) {
|
||||
res.sendFile(path.join(__dirname, 'build', 'static', 'js', chunkFile));
|
||||
} else {
|
||||
return next();
|
||||
app.use(
|
||||
/^\/accounts\/static\/js\/([0-9]|[1-9][0-9]|[1-9][0-9][0-9])\.(.+)\.chunk\.js$/,
|
||||
function(req, res, next) {
|
||||
let baseUrls = req.baseUrl;
|
||||
baseUrls = baseUrls.split('/');
|
||||
|
||||
const fileName = baseUrls[baseUrls.length - 1];
|
||||
if (fileName) {
|
||||
res.sendFile(
|
||||
path.join(__dirname, 'build', 'static', 'js', fileName)
|
||||
);
|
||||
} else {
|
||||
return next();
|
||||
}
|
||||
}
|
||||
});
|
||||
app.use(/^\/dashboard\/static\/js\/main\.(.+)\.chunk\.js$/, function(
|
||||
);
|
||||
app.use(/^\/accounts\/static\/js\/main\.(.+)\.chunk\.js$/, function(
|
||||
req,
|
||||
res,
|
||||
next
|
||||
) {
|
||||
if (mainChunkFile) {
|
||||
res.sendFile(
|
||||
path.join(__dirname, 'build', 'static', 'js', mainChunkFile)
|
||||
);
|
||||
let baseUrls = req.baseUrl;
|
||||
baseUrls = baseUrls.split('/');
|
||||
|
||||
const fileName = baseUrls[baseUrls.length - 1];
|
||||
if (fileName) {
|
||||
res.sendFile(path.join(__dirname, 'build', 'static', 'js', fileName));
|
||||
} else {
|
||||
return next();
|
||||
}
|
||||
|
@ -21,26 +21,6 @@ const express = require('express');
|
||||
const path = require('path');
|
||||
const app = express();
|
||||
const cors = require('cors');
|
||||
const fs = require('fs');
|
||||
|
||||
let chunkFile, mainChunkFile;
|
||||
const directory = path.join(__dirname, 'build', 'static', 'js');
|
||||
fs.readdir(directory, function(err, files) {
|
||||
const chunkRegex = /2\.(.+)\.chunk\.(js)$/;
|
||||
const mainChunkRegex = /main\.(.+)\.chunk\.(js)$/;
|
||||
if (err) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Unable to scan directory: ', err);
|
||||
}
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
if (chunkRegex.test(files[i])) {
|
||||
chunkFile = files[i];
|
||||
}
|
||||
if (mainChunkRegex.test(files[i])) {
|
||||
mainChunkFile = files[i];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
app.use(cors());
|
||||
|
||||
@ -153,26 +133,33 @@ app.get(['/dashboard/status', '/status'], function(req, res) {
|
||||
|
||||
app.use(express.static(path.join(__dirname, 'build')));
|
||||
app.use('/dashboard', express.static(path.join(__dirname, 'build')));
|
||||
app.use(/^\/dashboard\/static\/js\/2\.(.+)\.chunk\.js$/, function(
|
||||
req,
|
||||
res,
|
||||
next
|
||||
) {
|
||||
if (chunkFile) {
|
||||
res.sendFile(path.join(__dirname, 'build', 'static', 'js', chunkFile));
|
||||
} else {
|
||||
return next();
|
||||
app.use(
|
||||
/^\/dashboard\/static\/js\/([0-9]|[1-9][0-9]|[1-9][0-9][0-9])\.(.+)\.chunk\.js$/,
|
||||
function(req, res, next) {
|
||||
let baseUrls = req.baseUrl;
|
||||
baseUrls = baseUrls.split('/');
|
||||
|
||||
const fileName = baseUrls[baseUrls.length - 1];
|
||||
if (fileName) {
|
||||
res.sendFile(
|
||||
path.join(__dirname, 'build', 'static', 'js', fileName)
|
||||
);
|
||||
} else {
|
||||
return next();
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
app.use(/^\/dashboard\/static\/js\/main\.(.+)\.chunk\.js$/, function(
|
||||
req,
|
||||
res,
|
||||
next
|
||||
) {
|
||||
if (mainChunkFile) {
|
||||
res.sendFile(
|
||||
path.join(__dirname, 'build', 'static', 'js', mainChunkFile)
|
||||
);
|
||||
let baseUrls = req.baseUrl;
|
||||
baseUrls = baseUrls.split('/');
|
||||
|
||||
const fileName = baseUrls[baseUrls.length - 1];
|
||||
if (fileName) {
|
||||
res.sendFile(path.join(__dirname, 'build', 'static', 'js', fileName));
|
||||
} else {
|
||||
return next();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user