frontend api url
This commit is contained in:
@@ -15,5 +15,11 @@ WORKDIR /usr/share/nginx/html
|
|||||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
COPY --from=build /app/dist ./
|
COPY --from=build /app/dist ./
|
||||||
|
|
||||||
|
ENV API_BASE_URL=""
|
||||||
|
|
||||||
|
COPY docker-entrypoint.sh /docker-entrypoint.sh
|
||||||
|
RUN chmod +x /docker-entrypoint.sh
|
||||||
|
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
|
ENTRYPOINT ["/docker-entrypoint.sh"]
|
||||||
CMD ["nginx", "-g", "daemon off;"]
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
<title>Papercrate</title>
|
<title>Papercrate</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<script src="/config.js"></script>
|
||||||
<main id="app"></main>
|
<main id="app"></main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -22,7 +22,12 @@ import {
|
|||||||
} from 'react-router-dom';
|
} from 'react-router-dom';
|
||||||
import './styles.css';
|
import './styles.css';
|
||||||
|
|
||||||
const API_ROOT = (process.env.API_BASE_URL || '').replace(/\/$/, '');
|
const runtimeApiBase =
|
||||||
|
typeof window !== 'undefined' && window.__PAPERCRATE_API_BASE_URL
|
||||||
|
? window.__PAPERCRATE_API_BASE_URL
|
||||||
|
: '';
|
||||||
|
|
||||||
|
const API_ROOT = (runtimeApiBase || process.env.API_BASE_URL || '').replace(/\/$/, '');
|
||||||
|
|
||||||
const api = axios.create({
|
const api = axios.create({
|
||||||
baseURL: API_ROOT ? `${API_ROOT}/api` : '/api',
|
baseURL: API_ROOT ? `${API_ROOT}/api` : '/api',
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ const dotenv = require('dotenv');
|
|||||||
|
|
||||||
const env = dotenv.config({ path: path.resolve(__dirname, '.env.local') }).parsed || {};
|
const env = dotenv.config({ path: path.resolve(__dirname, '.env.local') }).parsed || {};
|
||||||
|
|
||||||
const API_BASE_URL =
|
const DEFAULT_DEV_API = 'http://127.0.0.1:3000';
|
||||||
env.API_BASE_URL || process.env.API_BASE_URL || 'http://127.0.0.1:3000';
|
|
||||||
|
const API_BASE_URL = env.API_BASE_URL || process.env.API_BASE_URL || '';
|
||||||
|
const devServerApiTarget = API_BASE_URL || DEFAULT_DEV_API;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
entry: './src/index.jsx',
|
entry: './src/index.jsx',
|
||||||
@@ -50,7 +52,7 @@ module.exports = {
|
|||||||
proxy: [
|
proxy: [
|
||||||
{
|
{
|
||||||
context: ['/api'],
|
context: ['/api'],
|
||||||
target: API_BASE_URL,
|
target: devServerApiTarget,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user