feat: refactor cc-server-core and fix binding registry
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
fd6c0e74cb
commit
8bde967d81
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@
|
|||||||
/dist
|
/dist
|
||||||
/package-lock.json
|
/package-lock.json
|
||||||
/yarn.lock
|
/yarn.lock
|
||||||
|
/*.log
|
@ -7,7 +7,7 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"registry": "https://repo.yumc.pw/repository/npm/"
|
"registry": "https://repo.yumc.pw/repository/npm-hosted/"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
"registry": "https://repo.yumc.pw/repository/npm-hosted/"
|
"registry": "https://repo.yumc.pw/repository/npm-hosted/"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "npx ts-node-dev --respawn --prefer-ts --debounce=1500 src/index.ts",
|
"dev": "npx ts-node-dev --respawn --prefer-ts --debounce=1500 src/server.ts",
|
||||||
"watch": "npx tsc --watch",
|
"watch": "npx tsc --watch",
|
||||||
"build": "rimraf dist && npx tsc",
|
"build": "rimraf dist && npx tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
|
@ -1,33 +1,45 @@
|
|||||||
import 'reflect-metadata';
|
import 'reflect-metadata';
|
||||||
import { InversifyExpressServer, getRouteInfo } from 'inversify-express-utils';
|
import * as express from "express";
|
||||||
|
import { InversifyExpressServer, interfaces, getRouteInfo } from 'inversify-express-utils';
|
||||||
import * as bodyParser from 'body-parser';
|
import * as bodyParser from 'body-parser';
|
||||||
import { rebuildServer } from 'cc-server-binding'
|
import { rebuildServer } from 'cc-server-binding'
|
||||||
import { container, buildProviderModule } from 'cc-server-ioc';
|
import { container, buildProviderModule } from 'cc-server-ioc';
|
||||||
import * as prettyjson from "prettyjson";
|
import * as prettyjson from "prettyjson";
|
||||||
|
|
||||||
import './function/handle';
|
export class CcServerBoot {
|
||||||
|
private server: InversifyExpressServer;
|
||||||
|
private serverInstance: express.Application;
|
||||||
|
constructor() {
|
||||||
|
container.load(buildProviderModule());
|
||||||
|
// start the server
|
||||||
|
this.server = new InversifyExpressServer(container);
|
||||||
|
this.server.setConfig((app) => {
|
||||||
|
app.use(bodyParser.urlencoded({
|
||||||
|
extended: true
|
||||||
|
}));
|
||||||
|
app.use(bodyParser.json());
|
||||||
|
app.use(bodyParser.raw());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
container.load(buildProviderModule());
|
public setConfig(fn: interfaces.ConfigFunction) {
|
||||||
|
this.server.setConfig(fn)
|
||||||
|
}
|
||||||
|
|
||||||
// start the server
|
public setErrorConfig(fn: interfaces.ConfigFunction) {
|
||||||
let server = new InversifyExpressServer(container);
|
this.server.setErrorConfig(fn)
|
||||||
|
}
|
||||||
|
|
||||||
server.setConfig((app) => {
|
public build() {
|
||||||
app.use(bodyParser.urlencoded({
|
this.serverInstance = this.server.build();
|
||||||
extended: true
|
rebuildServer(container);
|
||||||
}));
|
return this.serverInstance;
|
||||||
app.use(bodyParser.json());
|
}
|
||||||
app.use(bodyParser.raw());
|
|
||||||
});
|
|
||||||
|
|
||||||
let serverInstance = server.build();
|
public start() {
|
||||||
|
const routeInfo = getRouteInfo(container);
|
||||||
rebuildServer(container);
|
console.log(prettyjson.render({ routes: routeInfo }));
|
||||||
|
this.serverInstance.listen(80);
|
||||||
const routeInfo = getRouteInfo(container);
|
console.log('Server started on port 80 :)');
|
||||||
|
}
|
||||||
console.log(prettyjson.render({ routes: routeInfo }));
|
}
|
||||||
|
|
||||||
serverInstance.listen(80);
|
|
||||||
|
|
||||||
console.log('Server started on port 80 :)');
|
|
||||||
|
8
packages/cc-server-core/src/server.ts
Normal file
8
packages/cc-server-core/src/server.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { CcServerBoot } from './index'
|
||||||
|
|
||||||
|
import './function/handle';
|
||||||
|
|
||||||
|
let server = new CcServerBoot();
|
||||||
|
|
||||||
|
server.build();
|
||||||
|
server.start();
|
Loading…
Reference in New Issue
Block a user