chore: env

This commit is contained in:
chenos 2022-03-06 17:29:20 +08:00
parent c410c188a3
commit 5164f85484
7 changed files with 116 additions and 4 deletions

21
Dockerfile Normal file
View File

@ -0,0 +1,21 @@
FROM node:12.20.0-stretch
WORKDIR /app
# COPY . /app
RUN ls -a
RUN npm config set registry https://registry.npm.taobao.org
RUN yarn config set registry https://registry.npm.taobao.org
# RUN npm install
# RUN npm run bootstrap
# RUN npm run build
# # Install app dependencies
# ENV NPM_CONFIG_LOGLEVEL warn
# RUN yarn install
# # Show current folder structure in logs
RUN ls -a
# CMD [ "npm", "run", "serve" ]

39
docker-compose.yml Normal file
View File

@ -0,0 +1,39 @@
version: "3"
networks:
nocobase:
driver: bridge
services:
adminer:
image: adminer
restart: always
networks:
- nocobase
ports:
- ${ADMINER_PORT}:8080
postgres:
image: postgres:10
restart: always
ports:
- "${DB_POSTGRES_PORT}:5432"
networks:
- nocobase
command: postgres -c wal_level=logical
environment:
POSTGRES_USER: ${DB_USER}
POSTGRES_DB: ${DB_DATABASE}
POSTGRES_PASSWORD: ${DB_PASSWORD}
nocobase:
build:
context: .
dockerfile: Dockerfile
networks:
- nocobase
command: [ "yarn", "start" ]
working_dir: /app
env_file: ./.env
volumes:
- ./:/app
expose:
- 8000
ports:
- "${APP_PORT}:8000"

View File

@ -65,8 +65,6 @@ if (process.argv.length < 3) {
process.argv.push('start', '--port', process.env.API_PORT || 12302); process.argv.push('start', '--port', process.env.API_PORT || 12302);
} }
console.log(process.argv);
api.parse(process.argv).then(() => { api.parse(process.argv).then(() => {
console.log(`${new Date().toLocaleTimeString()} Start-up time: ${(Date.now() - start) / 1000}s`); console.log(`${new Date().toLocaleTimeString()} Start-up time: ${(Date.now() - start) / 1000}s`);
}); });

View File

@ -1,9 +1,25 @@
import dotenv from 'dotenv';
import { resolve } from 'path'; import { resolve } from 'path';
import { defineConfig } from 'umi'; import { defineConfig } from 'umi';
import { getUmiConfig } from '../utils/src/umiConfig';
dotenv.config({
path: resolve(__dirname, '../../.env'),
});
process.env.MFSU_AD = 'none'; process.env.MFSU_AD = 'none';
const umiConfig = getUmiConfig();
export default defineConfig({ export default defineConfig({
define: {
...umiConfig.define,
},
// only proxy when using `umi dev`
// if the assets are built, will not proxy
proxy: {
...umiConfig.proxy,
},
nodeModulesTransform: { nodeModulesTransform: {
type: 'none', type: 'none',
}, },

View File

@ -1,7 +1,7 @@
import { APIClient } from '@nocobase/client'; import { APIClient } from '@nocobase/client';
const apiClient = new APIClient({ const apiClient = new APIClient({
baseURL: `http://localhost:3000/api/`, baseURL: process.env.API_BASE_URL,
}); });
export default apiClient; export default apiClient;

View File

@ -1,5 +1,7 @@
export * from './merge'; export * from './merge';
export * from './mixin'; export * from './mixin';
export * from './mixin/AsyncEmitter'; export * from './mixin/AsyncEmitter';
export * from './uid';
export * from './registry'; export * from './registry';
export * from './uid';
export * from './umiConfig';

View File

@ -0,0 +1,36 @@
export function getUmiConfig() {
const { API_PORT, API_BASE_URL } = process.env;
const API_BASE_PATH = process.env.API_BASE_PATH || '/api/';
const PROXY_TARGET_URL = process.env.PROXY_TARGET_URL || `http://127.0.0.1:${API_PORT}`;
const LOCAL_STORAGE_BASE_URL = process.env.LOCAL_STORAGE_BASE_URL || '/uploads';
function getLocalStorageProxy() {
if (LOCAL_STORAGE_BASE_URL.startsWith('http')) {
return {};
}
return {
[LOCAL_STORAGE_BASE_URL]: {
target: PROXY_TARGET_URL,
changeOrigin: true,
},
};
}
return {
define: {
'process.env.API_BASE_URL': API_BASE_URL || API_BASE_PATH,
},
// only proxy when using `umi dev`
// if the assets are built, will not proxy
proxy: {
[API_BASE_PATH]: {
target: PROXY_TARGET_URL,
changeOrigin: true,
pathRewrite: { [`^${API_BASE_PATH}`]: API_BASE_PATH },
},
// for local storage
...getLocalStorageProxy(),
},
};
}