|
|
@ -9,7 +9,6 @@ import cookieParser from 'cookie-parser'; |
|
|
|
import debug from 'debug'; |
|
|
|
import debug from 'debug'; |
|
|
|
import * as express from 'express'; |
|
|
|
import * as express from 'express'; |
|
|
|
import { Router } from 'express'; |
|
|
|
import { Router } from 'express'; |
|
|
|
import importFresh from 'import-fresh'; |
|
|
|
|
|
|
|
import morgan from 'morgan'; |
|
|
|
import morgan from 'morgan'; |
|
|
|
import NcToolGui from 'nc-lib-gui'; |
|
|
|
import NcToolGui from 'nc-lib-gui'; |
|
|
|
import requestIp from 'request-ip'; |
|
|
|
import requestIp from 'request-ip'; |
|
|
@ -95,7 +94,6 @@ export default class Noco { |
|
|
|
|
|
|
|
|
|
|
|
public projectBuilders: Array<NcProjectBuilderCE | NcProjectBuilderEE> = []; |
|
|
|
public projectBuilders: Array<NcProjectBuilderCE | NcProjectBuilderEE> = []; |
|
|
|
private apiBuilders: Array<RestApiBuilder | GqlApiBuilder> = []; |
|
|
|
private apiBuilders: Array<RestApiBuilder | GqlApiBuilder> = []; |
|
|
|
private ncToolApi; |
|
|
|
|
|
|
|
private config: NcConfig; |
|
|
|
private config: NcConfig; |
|
|
|
private requestContext: any; |
|
|
|
private requestContext: any; |
|
|
|
|
|
|
|
|
|
|
@ -228,10 +226,7 @@ export default class Noco { |
|
|
|
req.ncProjectId = req?.query?.project_id || req?.body?.project_id; |
|
|
|
req.ncProjectId = req?.query?.project_id || req?.body?.project_id; |
|
|
|
next(); |
|
|
|
next(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
/* this.router.use(this.config.dashboardPath, (req: any, _res, next) => { |
|
|
|
|
|
|
|
req.ncProjectId = req?.body?.project_id; |
|
|
|
|
|
|
|
next(); |
|
|
|
|
|
|
|
})*/ |
|
|
|
|
|
|
|
this.router.use(`/nc/:project_id/*`, (req: any, _res, next) => { |
|
|
|
this.router.use(`/nc/:project_id/*`, (req: any, _res, next) => { |
|
|
|
req.ncProjectId = req.ncProjectId || req.params.project_id; |
|
|
|
req.ncProjectId = req.ncProjectId || req.params.project_id; |
|
|
|
next(); |
|
|
|
next(); |
|
|
@ -240,23 +235,10 @@ export default class Noco { |
|
|
|
|
|
|
|
|
|
|
|
/******************* Middlewares : end *******************/ |
|
|
|
/******************* Middlewares : end *******************/ |
|
|
|
|
|
|
|
|
|
|
|
// await this.initProjectBuilders();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const runTimeHandler = this.handleRuntimeChanges(progressCallback);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// this.ncToolApi.addListener(runTimeHandler);
|
|
|
|
|
|
|
|
// this.metaMgr.setListener(runTimeHandler);
|
|
|
|
|
|
|
|
// this.metaMgrv2.setListener(runTimeHandler);
|
|
|
|
|
|
|
|
// await this.metaMgr.initHandler(this.router);
|
|
|
|
|
|
|
|
// await this.metaMgrv2.initHandler(this.router);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await NcPluginMgrv2.init(Noco.ncMeta); |
|
|
|
await NcPluginMgrv2.init(Noco.ncMeta); |
|
|
|
registerMetaApis(this.router, server); |
|
|
|
registerMetaApis(this.router, server); |
|
|
|
|
|
|
|
|
|
|
|
// this.router.use(
|
|
|
|
|
|
|
|
// this.config.dashboardPath,
|
|
|
|
|
|
|
|
// await this.ncToolApi.expressMiddleware()
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
this.router.use(NcToolGui.expressMiddleware(this.config.dashboardPath)); |
|
|
|
this.router.use(NcToolGui.expressMiddleware(this.config.dashboardPath)); |
|
|
|
this.router.get('/', (_req, res) => |
|
|
|
this.router.get('/', (_req, res) => |
|
|
|
res.redirect(this.config.dashboardPath) |
|
|
|
res.redirect(this.config.dashboardPath) |
|
|
@ -312,118 +294,6 @@ export default class Noco { |
|
|
|
this.requestContext = context; |
|
|
|
this.requestContext = context; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected handleRuntimeChanges(_progressCallback: Function) { |
|
|
|
|
|
|
|
return async (data): Promise<any> => { |
|
|
|
|
|
|
|
switch (data?.req?.api) { |
|
|
|
|
|
|
|
case 'projectCreateByWeb': |
|
|
|
|
|
|
|
case 'projectCreateByOneClick': |
|
|
|
|
|
|
|
case 'projectCreateByWebWithXCDB': |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// || data?.req?.args?.project?.title || data?.req?.args?.title
|
|
|
|
|
|
|
|
const project = await Noco.ncMeta.projectGetById(data?.res?.id); |
|
|
|
|
|
|
|
const builder = new NcProjectBuilder(this, this.config, project); |
|
|
|
|
|
|
|
this.projectBuilders.push(builder); |
|
|
|
|
|
|
|
await builder.init(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
// create project builder for newly imported project
|
|
|
|
|
|
|
|
// duplicated code - projectCreateByWeb
|
|
|
|
|
|
|
|
case 'xcMetaTablesImportZipToLocalFsAndDb': |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (data.req?.freshImport) { |
|
|
|
|
|
|
|
const project = await Noco.ncMeta.projectGetById( |
|
|
|
|
|
|
|
data?.req?.project_id |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
const builder = new NcProjectBuilder(this, this.config, project); |
|
|
|
|
|
|
|
this.projectBuilders.push(builder); |
|
|
|
|
|
|
|
await builder.init(true); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
const projectBuilder = this.projectBuilders.find( |
|
|
|
|
|
|
|
(pb) => pb.id == data.req?.project_id |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
return projectBuilder?.handleRunTimeChanges(data); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'projectUpdateByWeb': |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const projectId = data.req?.project_id; |
|
|
|
|
|
|
|
const project = await Noco._ncMeta.projectGetById( |
|
|
|
|
|
|
|
data?.req?.project_id |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
const projectBuilder = this.projectBuilders.find( |
|
|
|
|
|
|
|
(pb) => pb.id === projectId |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
projectBuilder.updateConfig(project.config); |
|
|
|
|
|
|
|
await projectBuilder.reInit(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'projectChangeEnv': |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
this.config = importFresh( |
|
|
|
|
|
|
|
path.join(process.cwd(), 'config.xc.json') |
|
|
|
|
|
|
|
) as NcConfig; |
|
|
|
|
|
|
|
this.config.toolDir = this.config.toolDir || process.cwd(); |
|
|
|
|
|
|
|
Noco._ncMeta.setConfig(this.config); |
|
|
|
|
|
|
|
this.metaMgr.setConfig(this.config); |
|
|
|
|
|
|
|
Object.assign(process.env, { |
|
|
|
|
|
|
|
NODE_ENV: (this.env = this.config.workingEnv), |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
this.router.stack.splice(0, this.router.stack.length); |
|
|
|
|
|
|
|
this.ncToolApi.destroy(); |
|
|
|
|
|
|
|
this.ncToolApi.reInitialize(this.config); |
|
|
|
|
|
|
|
// await this.init({progressCallback});
|
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
console.log(e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default: { |
|
|
|
|
|
|
|
const projectBuilder = this.projectBuilders.find( |
|
|
|
|
|
|
|
(pb) => pb.id == data.req?.project_id |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
return projectBuilder?.handleRunTimeChanges(data); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected async initProjectBuilders() { |
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
|
|
|
const RestAuthCtrl = process.env.EE ? RestAuthCtrlEE : RestAuthCtrlCE; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.projectBuilders.splice(0, this.projectBuilders.length); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// await new RestAuthCtrl(
|
|
|
|
|
|
|
|
// this as any,
|
|
|
|
|
|
|
|
// Noco._ncMeta?.knex,
|
|
|
|
|
|
|
|
// this.config?.meta?.db,
|
|
|
|
|
|
|
|
// this.config,
|
|
|
|
|
|
|
|
// Noco._ncMeta
|
|
|
|
|
|
|
|
// ).init();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.router.use(this.projectRouter); |
|
|
|
|
|
|
|
const projects = await Noco._ncMeta.projectList(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (const project of projects) { |
|
|
|
|
|
|
|
const projectBuilder = new NcProjectBuilder(this, this.config, project); |
|
|
|
|
|
|
|
this.projectBuilders.push(projectBuilder); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
let i = 0; |
|
|
|
|
|
|
|
for (const builder of this.projectBuilders) { |
|
|
|
|
|
|
|
if ( |
|
|
|
|
|
|
|
projects[i].status === 'started' || |
|
|
|
|
|
|
|
projects[i].status === 'starting' |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
await builder.init(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
i++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async syncMigration(): Promise<void> { |
|
|
|
private async syncMigration(): Promise<void> { |
|
|
|
if ( |
|
|
|
if ( |
|
|
|
this.config?.toolDir |
|
|
|
this.config?.toolDir |
|
|
|