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
|
||||
/package-lock.json
|
||||
/yarn.lock
|
||||
/*.log
|
@ -7,7 +7,7 @@
|
||||
"license": "ISC",
|
||||
"main": "dist/index.js",
|
||||
"publishConfig": {
|
||||
"registry": "https://repo.yumc.pw/repository/npm/"
|
||||
"registry": "https://repo.yumc.pw/repository/npm-hosted/"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -10,7 +10,7 @@
|
||||
"registry": "https://repo.yumc.pw/repository/npm-hosted/"
|
||||
},
|
||||
"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",
|
||||
"build": "rimraf dist && npx tsc",
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
|
@ -1,33 +1,45 @@
|
||||
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 { rebuildServer } from 'cc-server-binding'
|
||||
import { container, buildProviderModule } from 'cc-server-ioc';
|
||||
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
|
||||
let server = new InversifyExpressServer(container);
|
||||
public setErrorConfig(fn: interfaces.ConfigFunction) {
|
||||
this.server.setErrorConfig(fn)
|
||||
}
|
||||
|
||||
server.setConfig((app) => {
|
||||
app.use(bodyParser.urlencoded({
|
||||
extended: true
|
||||
}));
|
||||
app.use(bodyParser.json());
|
||||
app.use(bodyParser.raw());
|
||||
});
|
||||
public build() {
|
||||
this.serverInstance = this.server.build();
|
||||
rebuildServer(container);
|
||||
return this.serverInstance;
|
||||
}
|
||||
|
||||
let serverInstance = server.build();
|
||||
|
||||
rebuildServer(container);
|
||||
|
||||
const routeInfo = getRouteInfo(container);
|
||||
|
||||
console.log(prettyjson.render({ routes: routeInfo }));
|
||||
|
||||
serverInstance.listen(80);
|
||||
|
||||
console.log('Server started on port 80 :)');
|
||||
public start() {
|
||||
const routeInfo = getRouteInfo(container);
|
||||
console.log(prettyjson.render({ routes: routeInfo }));
|
||||
this.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