fix and simplify baseurl
This commit is contained in:
8
.env
8
.env
@ -1,9 +1,7 @@
|
||||
|
||||
#NODE_TLS_REJECT_UNAUTHORIZED='0'
|
||||
# SSL_ENABLED=false
|
||||
# NEXT_PUBLIC_HOST=localhost
|
||||
# NEXT_PUBLIC_PORT=3003
|
||||
# PUBLIC_URL=http://localhost:3003
|
||||
# HOST=localhost
|
||||
# PORT=3003
|
||||
# NEXT_PUBLIC_PUBLIC_URL=http://localhost:3003
|
||||
|
||||
# Linux: `openssl rand -hex 32` or go to https://generate-secret.now.sh/32
|
||||
NEXTAUTH_SECRET=ed8a9681efc414df89dfd03cd188ed58
|
||||
|
@ -1,9 +0,0 @@
|
||||
SSL_ENABLED=false
|
||||
NEXT_PUBLIC_PORT=
|
||||
NEXT_PUBLIC_HOST=staging.mwhitnessing.com
|
||||
PUBLIC_URL=https://staging.mwhitnessing.com
|
||||
|
||||
# Linux: `openssl rand -hex 32` or go to https://generate-secret.now.sh/32
|
||||
NEXTAUTH_SECRET=1dd8a5457970d1dda50600be28e935ecc4513ff27c49c431849e6746f158d638
|
||||
# ? do we need to duplicate this? already defined in the deoployment yml file
|
||||
DATABASE_URL=mysql://jwpwsofia_demo:dwxhns9p9vp248@mariadb:3306/jwpwsofia_demo
|
@ -1,9 +1,9 @@
|
||||
NODE_TLS_REJECT_UNAUTHORIZED=0
|
||||
# NODE_EXTRA_CA_CERTS=C:\\Users\\popov\\AppData\\Local\\mkcert
|
||||
NEXT_PUBLIC_PROTOCOL=https
|
||||
NEXT_PUBLIC_PORT=3003
|
||||
NEXT_PUBLIC_HOST=localhost
|
||||
PUBLIC_URL=https://localhost:3003
|
||||
PROTOCOL=https
|
||||
PORT=3003
|
||||
HOST=localhost
|
||||
NEXT_PUBLIC_PUBLIC_URL=https://localhost:3003
|
||||
|
||||
SSL_KEY=./certificates/localhost-key.pem
|
||||
SSL_CERT=./certificates/localhost.pem
|
||||
|
@ -1,7 +1,7 @@
|
||||
NEXT_PUBLIC_PORT=
|
||||
NEXT_PUBLIC_HOST=sofia.mwhitnessing.com
|
||||
SSL_ENABLED=false # we're behind a reverse proxy. SSL is handled by the proxy
|
||||
PUBLIC_URL= https://sofia.mwhitnessing.com
|
||||
PORT=
|
||||
HOST=sofia.mwhitnessing.com
|
||||
PROTOCOL=http # we're behind a reverse proxy. SSL is handled by the proxy
|
||||
NEXT_PUBLIC_PUBLIC_URL= https://sofia.mwhitnessing.com
|
||||
|
||||
# Linux: `openssl rand -hex 32` or go to https://generate-secret.now.sh/32
|
||||
NEXTAUTH_SECRET=1dd8a5457970d1dda50600be28e935ecc4513ff27c49c431849e6746f158d638
|
||||
|
@ -1,7 +1,7 @@
|
||||
NEXT_PUBLIC_PROTOCOL=http
|
||||
NEXT_PUBLIC_PORT=
|
||||
NEXT_PUBLIC_HOST=staging.mwhitnessing.com
|
||||
PUBLIC_URL=https://staging.mwhitnessing.com
|
||||
PROTOCOL=http
|
||||
HOST=staging.mwhitnessing.com
|
||||
PORT=
|
||||
NEXT_PUBLIC_PUBLIC_URL=https://staging.mwhitnessing.com
|
||||
|
||||
# Linux: `openssl rand -hex 32` or go to https://generate-secret.now.sh/32
|
||||
NEXTAUTH_SECRET=1dd8a5457970d1dda50600be28e935ecc4513ff27c49c431849e6746f158d638
|
||||
|
@ -12,7 +12,7 @@ module.exports = {
|
||||
pageExtensions: ['ts', 'tsx', 'md', 'mdx'], // Replace `jsx?` with `tsx?`
|
||||
env: {
|
||||
env: process.env.NODE_ENV,
|
||||
server: process.env.NEXT_PUBLIC_PROTOCOL + '://' + process.env.NEXT_PUBLIC_HOST + ':' + process.env.NEXT_PUBLIC_PORT + '',
|
||||
server: process.env.NEXT_PUBLIC_PUBLIC_URL
|
||||
},
|
||||
webpack(config, { isServer }) {
|
||||
|
||||
|
14
server.js
14
server.js
@ -35,16 +35,16 @@ require('dotenv').config({
|
||||
|
||||
console.log("process.env.NODE_ENV = ", process.env.NODE_ENV);
|
||||
|
||||
const PROTOCOL = process.env.NEXT_PUBLIC_PROTOCOL;
|
||||
const PORT = process.env.NEXT_PUBLIC_PORT || 3000;
|
||||
const HOST = process.env.NEXT_PUBLIC_HOST;
|
||||
const PROTOCOL = process.env.PROTOCOL;
|
||||
const PORT = process.env.PORT || 3000;
|
||||
const HOST = process.env.HOST;
|
||||
|
||||
const dev = process.env.NODE_ENV !== "production";
|
||||
const nextApp = next({ dev });
|
||||
const nextHandler = nextApp.getRequestHandler();
|
||||
console.log("process.env.NEXT_PUBLIC_PROTOCOL = ", process.env.NEXT_PUBLIC_PROTOCOL);
|
||||
console.log("process.env.PUBLIC_URL = ", process.env.PUBLIC_URL);
|
||||
console.log("process.env.NEXT_PUBLIC_PORT = ", process.env.NEXT_PUBLIC_PORT);
|
||||
console.log("process.env.PROTOCOL = ", process.env.PROTOCOL);
|
||||
console.log("process.env.PUBLIC_URL = ", process.env.NEXT_PUBLIC_PUBLIC_URL);
|
||||
console.log("process.env.PORT = ", process.env.PORT);
|
||||
console.log("process.env.TELEGRAM_BOT = ", process.env.TELEGRAM_BOT);
|
||||
|
||||
//require('module-alias/register');
|
||||
@ -66,7 +66,7 @@ const prisma = common.getPrismaClient();
|
||||
const server = express();
|
||||
|
||||
//check if ssl is enabled
|
||||
if (process.env.NEXT_PUBLIC_PROTOCOL === 'https') {
|
||||
if (process.env.PROTOCOL === 'https') {
|
||||
console.log("SSL_ENABLED = true");
|
||||
// Redirect from http to https
|
||||
// server.use((req, res, next) => {
|
||||
|
@ -76,39 +76,7 @@ exports.setBaseUrl = function (req) {
|
||||
};
|
||||
|
||||
exports.getBaseUrl = function (relative = "", req = null) {
|
||||
if (typeof window === 'undefined') {
|
||||
// Server-side logic
|
||||
// Read the base URL from env (PUBLIC_URL):
|
||||
return process.env.PUBLIC_URL + relative;
|
||||
|
||||
// const filePath = path.join(__dirname, 'baseUrl.txt');
|
||||
|
||||
// try {
|
||||
// if (fs.existsSync(filePath)) {
|
||||
// const baseUrl = fs.readFileSync(filePath, 'utf8').trim();
|
||||
// const fullUrl = relative ? new URL(relative, baseUrl).toString() : baseUrl;
|
||||
// return fullUrl;
|
||||
// } else {
|
||||
// if (req) {
|
||||
// // Assuming setBaseUrl is defined somewhere in this file
|
||||
// const baseUrl = exports.setBaseUrl(req);
|
||||
// return `${baseUrl}/${relative.replace(/^\/|\/$/g, '')}`;
|
||||
// }
|
||||
// console.log('Base URL file does not exist.');
|
||||
// return null;
|
||||
// }
|
||||
// } catch (error) {
|
||||
// console.error('Error reading the base URL file:', error);
|
||||
// return null;
|
||||
// }
|
||||
} else {
|
||||
// Client-side logic
|
||||
// Fetch the base URL from the server endpoint you've set up
|
||||
const baseUrl = window.location.origin;
|
||||
const fullUrl = relative ? `${baseUrl}/${relative.replace(/^\/|\/$/g, '')}` : baseUrl;
|
||||
//console.log("getBaseUrl()=", fullUrl);
|
||||
return fullUrl.toString();
|
||||
}
|
||||
return process.env.NEXT_PUBLIC_PUBLIC_URL + relative;
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user