Skip to content

Commit

Permalink
Merge pull request #620 from idurar/fix/proxy-bugs
Browse files Browse the repository at this point in the history
Fix/proxy bugs
  • Loading branch information
salahlalami authored Oct 30, 2023
2 parents 44fc287 + 39751a0 commit b3efa39
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 164 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
3 changes: 2 additions & 1 deletion frontend/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# to connect your frontend to remote backend server
VITE_BACKEND_SERVER="http://your_backend_url_server.com/"
VITE_BACKEND_SERVER="http://your_backend_url_server.com/"
PROD = false
123 changes: 10 additions & 113 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"cross-env": "7.0.3",
"currency.js": "2.0.4",
"history": "4.10.1",
"http-proxy-middleware": "^2.0.6",
"just-compare": "^2.3.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
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);
99 changes: 59 additions & 40 deletions frontend/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,67 @@
import path from 'path';

// import { defineConfig, loadEnv } from 'vite';
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';

// https://vitejs.dev/config/
// export default ({ mode }) => {
// process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };
// const config = {
// plugins: [react()],
// resolve: {
// base: '/',
// alias: {
// '@': path.resolve(__dirname, 'src'),
// },
// },
// server: {
// proxy: {
// '/api': {
// target: 'http://dev-server.idurarapp.com/',
// changeOrigin: false,
// secure: false,
// },
// },
// },
// };
// return defineConfig(config);
// };
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
resolve: {
base: '/',
alias: {
'@': path.resolve(__dirname, 'src'),
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: {
base: '/',
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
},
server: {
proxy: {
'/api': {
target: 'http://dev-server.idurarapp.com/',
changeOrigin: true,
// rewrite: (path) => path.replace(/^\/api/, ''),
server: {
proxy: {
'/api': {
target: proxy_url,
changeOrigin: true,
secure: false,
},
},
},
},
});
};
return defineConfig(config);
};
// https://vitejs.dev/config/

// export default defineConfig(({ command, mode }) => {
// // Load env file based on `mode` in the current working directory.
// // Set the third parameter to '' to load all env regardless of the `VITE_` prefix.
// const env = loadEnv(mode, process.cwd(), '');
// return {
// // vite config
// define: {
// __APP_ENV__: JSON.stringify(env.APP_ENV),
// },
// };
// });

// export default defineConfig({
// plugins: [react()],
// resolve: {
// base: '/',
// alias: {
// '@': path.resolve(__dirname, 'src'),
// },
// },
// server: {
// proxy: {
// '/api': {
// target: import.meta.env.VITE_BACKEND_SERVER,
// changeOrigin: true,
// secure: false,
// },
// },
// },
// });

0 comments on commit b3efa39

Please sign in to comment.