set base URL dynamiically
This commit is contained in:
@ -55,20 +55,39 @@ exports.isValidPhoneNumber = function (phone) {
|
||||
return false;
|
||||
}
|
||||
exports.getBaseUrl = function (relative = "") {
|
||||
const host = process.env.NEXT_PUBLIC_HOST || '127.0.0.1';
|
||||
const port = process.env.NEXT_PUBLIC_PORT ? `:${process.env.NEXT_PUBLIC_PORT}` : '';
|
||||
const protocol = process.env.NEXT_PUBLIC_PROTOCOL || "https"
|
||||
const filePath = path.join(__dirname, 'baseUrl.txt');
|
||||
|
||||
//const url = `${protocol}://${host}${port}/${relative.replace(/^\/|\/$/g, '')}/`;
|
||||
const isRelativeEmpty = !relative || relative.trim() === '';
|
||||
const formattedRelative = !isRelativeEmpty ? '/' + relative.replace(/^\/|\/$/g, '') : '';
|
||||
const url = `${protocol}://${host}${port}${formattedRelative}`;
|
||||
try {
|
||||
// Check if the base URL file exists
|
||||
if (fs.existsSync(filePath)) {
|
||||
// Read the base URL from the file
|
||||
const baseUrl = fs.readFileSync(filePath, 'utf8').trim();
|
||||
// If a relative path is provided, append it to the base URL
|
||||
const fullUrl = relative ? new URL(relative, baseUrl).toString() : baseUrl;
|
||||
return fullUrl;
|
||||
} else {
|
||||
console.log('Base URL file does not exist.');
|
||||
return null;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error reading the base URL file:', error);
|
||||
return null;
|
||||
}
|
||||
|
||||
// const host = process.env.NEXT_PUBLIC_HOST || '127.0.0.1';
|
||||
// const port = process.env.NEXT_PUBLIC_PORT ? `:${process.env.NEXT_PUBLIC_PORT}` : '';
|
||||
// const protocol = process.env.NEXT_PUBLIC_PROTOCOL || "https"
|
||||
|
||||
// //const url = `${protocol}://${host}${port}/${relative.replace(/^\/|\/$/g, '')}/`;
|
||||
// const isRelativeEmpty = !relative || relative.trim() === '';
|
||||
// const formattedRelative = !isRelativeEmpty ? '/' + relative.replace(/^\/|\/$/g, '') : '';
|
||||
// const url = `${protocol}://${host}${port}${formattedRelative}`;
|
||||
|
||||
|
||||
logger.debug("NODE_ENV = ", process.env.NODE_ENV, "protocol:", protocol);
|
||||
logger.debug("getBaseURL = ", url);
|
||||
// logger.debug("NODE_ENV = ", process.env.NODE_ENV, "protocol:", protocol);
|
||||
// logger.debug("getBaseURL = ", url);
|
||||
|
||||
return url;
|
||||
// return url;
|
||||
};
|
||||
|
||||
let prisma;
|
||||
|
Reference in New Issue
Block a user