Skip to content

Commit

Permalink
Merge pull request #619 from idurar/bugs/cross-deploy
Browse files Browse the repository at this point in the history
fixed
  • Loading branch information
salahlalami authored Oct 30, 2023
2 parents 3c5bfcc + 3b03235 commit e8a4c29
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@ const login = async (req, res) => {
try {
const { email, password } = req.body;

console.log('🚀 ~ file: app.js:33 ~ req.origin :', req.get('origin'));

// URL address
const address = req.get('origin');
console.log('🚀 ~ file: login.js:21 ~ login ~ address:', address);
console.log('🚀 ~ file: login.js:21 ~ login ~ req.hostname:', req.hostname);

// Call parse() method using url module
let urlObject = url.parse(address, true);
Expand All @@ -30,9 +26,6 @@ const login = async (req, res) => {
isLocalhost = true;
}

console.log('🚀 ~ file: login.js:22 ~ login ~ orginalHostname:', orginalHostname);

console.log('🚀 ~ file: login.js:20 ~ login ~ isLocalhost:', isLocalhost);
// validate
const objectSchema = Joi.object({
email: Joi.string()
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/___setupProxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createProxyMiddleware } from 'http-proxy-middleware';

export default function (app) {
app.use(
'/api',
createProxyMiddleware({
target:
import.meta.env.VITE_DEV_REMOTE == 'remote'
? import.meta.env.VITE_BACKEND_SERVER
: 'http://localhost/',
changeOrigin: true,
})
);
}
6 changes: 4 additions & 2 deletions frontend/src/config/serverApiConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ export const API_BASE_URL =
? import.meta.env.VITE_BACKEND_SERVER + 'api/'
: 'http://localhost:8888/api/';
export const BASE_URL =
import.meta.env.PROD || import.meta.env.VITE_DEV_REMOTE == 'remote'
import.meta.env.PROD || import.meta.env.VITE_DEV_REMOTE
? import.meta.env.VITE_BACKEND_SERVER
: 'http://localhost:8888/';
export const DOWNLOAD_BASE_URL =
import.meta.env.PROD || import.meta.env.VITE_DEV_REMOTE == 'remote'
import.meta.env.PROD || import.meta.env.VITE_DEV_REMOTE
? import.meta.env.VITE_BACKEND_SERVER + 'download/'
: 'http://localhost:8888/download/';
export const ACCESS_TOKEN_NAME = 'x-auth-token';

console.log('🚀 ~ file: serverApiConfig.js:2 ~ API_BASE_URL:', API_BASE_URL);
9 changes: 8 additions & 1 deletion frontend/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import react from '@vitejs/plugin-react';
// https://vitejs.dev/config/
export default ({ mode }) => {
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };

const proxy_url =
process.env.VITE_DEV_REMOTE === 'remote'
? process.env.VITE_BACKEND_SERVER
: 'http://localhost:8888/';

console.log('🚀 ~ file: vite.config.js:11 ~ proxy_url:', proxy_url);
const config = {
plugins: [react()],
resolve: {
Expand All @@ -17,7 +24,7 @@ export default ({ mode }) => {
server: {
proxy: {
'/api': {
target: process.env.VITE_BACKEND_SERVER,
target: proxy_url,
changeOrigin: true,
secure: false,
},
Expand Down

0 comments on commit e8a4c29

Please sign in to comment.