set base URL dynamiically
This commit is contained in:
13
server.js
13
server.js
@ -23,6 +23,9 @@ import('get-port').then(module => {
|
||||
});
|
||||
|
||||
process.env.TZ = 'Europe/Sofia';
|
||||
// Global variable to store the base URL
|
||||
let baseUrlGlobal;
|
||||
|
||||
|
||||
const PORT = process.env.NEXT_PUBLIC_PORT || 3000;
|
||||
const HOST = process.env.NEXT_PUBLIC_HOST;
|
||||
@ -71,6 +74,14 @@ app
|
||||
// Add the middleware to set 'x-forwarded-host' header
|
||||
server.use((req, res, next) => {
|
||||
req.headers['x-forwarded-host'] = req.headers['x-forwarded-host'] || req.headers.host;
|
||||
// ---------------
|
||||
if (!baseUrlGloball) {
|
||||
const protocol = req.headers['x-forwarded-proto'] || 'http';
|
||||
const host = req.headers.host;
|
||||
const baseUrl = `${protocol}://${host}`;
|
||||
baseUrlGlobal = baseUrl;
|
||||
fs.writeFileSync(path.join(__dirname, 'baseUrl.txt'), baseUrlGlobal, 'utf8');
|
||||
}
|
||||
next();
|
||||
});
|
||||
server.use("/favicon.ico", express.static("styles/favicon_io/favicon.ico"));
|
||||
@ -621,4 +632,4 @@ async function Stat() {
|
||||
|
||||
Stat();
|
||||
|
||||
|
||||
exports.baseUrlGlobal = baseUrlGlobal;
|
||||
|
Reference in New Issue
Block a user