feat: serve dist files for development
This commit is contained in:
parent
fd8c6f8e50
commit
c808c5b602
@ -18,6 +18,7 @@ API_PORT=23000
|
||||
|
||||
VERDACCIO_PORT=4873
|
||||
|
||||
APP_DIST=
|
||||
USE_STATIC_SERVER=true
|
||||
LOCAL_STORAGE_BASE_URL=http://localhost:23000/uploads
|
||||
STORAGE_BASE_URL=http://localhost:23000/uploads
|
||||
|
945
package-lock.json
generated
945
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -5,6 +5,8 @@
|
||||
"start": "cd packages/app && npm start",
|
||||
"start-server": "cd packages/api && npm start",
|
||||
"start-client": "cd packages/app && npx umi dev",
|
||||
"pm2-start": "npx pm2 start packages/api/lib/index.js",
|
||||
"build-app": "cd packages/app && npm run build",
|
||||
"bootstrap": "lerna bootstrap --no-ci",
|
||||
"build": "father-build",
|
||||
"clean": "lerna clean",
|
||||
@ -46,6 +48,7 @@
|
||||
"path-to-regexp": "^6.1.0",
|
||||
"pg": "^8.3.0",
|
||||
"pg-hstore": "^2.3.3",
|
||||
"pm2": "^4.5.6",
|
||||
"sequelize": "^6.3.4",
|
||||
"supertest": "^4.0.2",
|
||||
"ts-jest": "^26.1.2",
|
||||
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"name": "@nocobase/api",
|
||||
"version": "0.4.0-alpha.0",
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
"start": "nodemon",
|
||||
"db-migrate": "ts-node ./src/migrate.ts"
|
||||
@ -14,10 +15,11 @@
|
||||
"@nocobase/plugin-china-region": "^0.4.0-alpha.0",
|
||||
"@nocobase/plugin-collections": "^0.4.0-alpha.0",
|
||||
"@nocobase/plugin-file-manager": "^0.4.0-alpha.0",
|
||||
"@nocobase/plugin-permissions": "^0.4.0-alpha.0",
|
||||
"@nocobase/plugin-pages": "^0.4.0-alpha.0",
|
||||
"@nocobase/plugin-permissions": "^0.4.0-alpha.0",
|
||||
"@nocobase/plugin-users": "^0.4.0-alpha.0",
|
||||
"@nocobase/server": "^0.4.0-alpha.0"
|
||||
"@nocobase/server": "^0.4.0-alpha.0",
|
||||
"koa-static": "^5.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^2.0.6",
|
||||
|
@ -1,8 +1,6 @@
|
||||
import path from 'path';
|
||||
import dotenv from 'dotenv';
|
||||
import Api from '@nocobase/server/src';
|
||||
import actions from '@nocobase/actions/src';
|
||||
import { middlewares } from '@nocobase/actions/src';
|
||||
import Api from '@nocobase/server';
|
||||
|
||||
// @ts-ignore
|
||||
const sync = global.sync || {
|
||||
@ -14,6 +12,7 @@ const sync = global.sync || {
|
||||
|
||||
console.log('process.env.NOCOBASE_ENV', process.env.NOCOBASE_ENV);
|
||||
|
||||
// TODO: env 需要换种方式加载
|
||||
dotenv.config({
|
||||
path: path.resolve(__dirname, '../../../.env'),
|
||||
});
|
||||
@ -57,7 +56,7 @@ const plugins = [
|
||||
];
|
||||
|
||||
for (const plugin of plugins) {
|
||||
api.registerPlugin(plugin, [require(`${plugin}/src/server`).default]);
|
||||
api.registerPlugin(plugin, [require(`${plugin}/${__filename.endsWith('.ts') ? 'src' : 'lib'}/server`).default]);
|
||||
}
|
||||
|
||||
export default api;
|
||||
|
@ -1,5 +1,7 @@
|
||||
import api from './app';
|
||||
import actions from '../../actions/src';
|
||||
import actions from '@nocobase/actions';
|
||||
import send from 'koa-send';
|
||||
import serve from 'koa-static';
|
||||
|
||||
api.resourcer.use(async (ctx: actions.Context, next) => {
|
||||
const { actionName, resourceField, resourceName, fields = {} } = ctx.action.params;
|
||||
@ -29,27 +31,6 @@ api.resourcer.use(async (ctx: actions.Context, next) => {
|
||||
await next();
|
||||
});
|
||||
|
||||
// api.resourcer.use(async (ctx: actions.Context, next) => {
|
||||
// const { resourceField, resourceName, viewName, filter } = ctx.action.params;
|
||||
// // TODO: 需要补充默认视图的情况
|
||||
// let view: any;
|
||||
// if (viewName) {
|
||||
// view = await ctx.db.getModel('views').findOne({
|
||||
// where: {
|
||||
// collection_name: resourceField ? resourceField.options.target : resourceName,
|
||||
// name: viewName,
|
||||
// }
|
||||
// });
|
||||
// const viewFilter = view.get('filter');
|
||||
// if (viewFilter) {
|
||||
// const args = [viewFilter, filter].filter(Boolean);
|
||||
// ctx.action.setParam('filter', {and: args});
|
||||
// console.log(ctx.action.params.filter);
|
||||
// }
|
||||
// }
|
||||
// await next();
|
||||
// });
|
||||
|
||||
(async () => {
|
||||
await api.loadPlugins();
|
||||
|
||||
@ -81,6 +62,17 @@ api.resourcer.use(async (ctx: actions.Context, next) => {
|
||||
name: 'users',
|
||||
}});
|
||||
await api.database.getModel('automations').load();
|
||||
|
||||
api.use(async (ctx, next) => {
|
||||
if (!process.env.APP_DIST || !process.env.USE_STATIC_SERVER || process.env.USE_STATIC_SERVER === 'false') {
|
||||
return next();
|
||||
}
|
||||
await serve(process.env.APP_DIST)(ctx, next);
|
||||
if (ctx.status == 404) {
|
||||
return send(ctx, 'index.html', { root: process.env.APP_DIST });
|
||||
}
|
||||
});
|
||||
|
||||
api.listen(process.env.API_PORT, () => {
|
||||
console.log(`http://localhost:${process.env.API_PORT}/`);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user