feat: add cc-server-db
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "npx ts-node src/index.ts",
|
||||
"build": "npx tsc",
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
@@ -24,6 +25,8 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/body-parser": "^1.17.0",
|
||||
"@types/express": "^4.17.0",
|
||||
"ts-node": "^8.2.0"
|
||||
}
|
||||
},
|
||||
"gitHead": "7d84393a3cb6be6be9ed51d71f12677d2d7d0728"
|
||||
}
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
import {
|
||||
controller, httpGet, httpPost, httpPut, httpDelete
|
||||
controller, httpGet, httpPost
|
||||
} from 'inversify-express-utils';
|
||||
import { inject } from 'inversify';
|
||||
import { MongoDBClient } from 'cc-server-db-mongo'
|
||||
import { DBClient } from 'cc-server-db'
|
||||
import 'cc-server-db-mongo'
|
||||
|
||||
@controller('/')
|
||||
export class UserController {
|
||||
constructor(
|
||||
@inject(MongoDBClient) private MongoDBClient: MongoDBClient
|
||||
@inject(DBClient) private client: DBClient
|
||||
) { }
|
||||
|
||||
@httpGet('/')
|
||||
public async getUsers(): Promise<any[]> {
|
||||
return []
|
||||
return this.client.find('users', {});
|
||||
}
|
||||
|
||||
@httpPost('/')
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"sourceRoot": "src",
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": false,
|
||||
"sourceMap": false,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"moduleResolution": "node",
|
||||
"noUnusedLocals": true
|
||||
},
|
||||
"compileOnSave": false,
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
@@ -1,19 +1,11 @@
|
||||
import 'reflect-metadata';
|
||||
import { InversifyExpressServer } from 'inversify-express-utils';
|
||||
import { Container } from 'inversify';
|
||||
import * as bodyParser from 'body-parser';
|
||||
import { container, buildProviderModule } from 'cc-server-ioc';
|
||||
|
||||
import './function/handle';
|
||||
import { METADATA_KEY } from 'cc-server-ioc';
|
||||
|
||||
// load everything needed to the Container
|
||||
let container = new Container();
|
||||
Reflect.defineMetadata(METADATA_KEY.container, container, Reflect)
|
||||
|
||||
// auto load service
|
||||
let services: Function[] = Reflect.getMetadata(METADATA_KEY.service, Reflect);
|
||||
for (const service of services) {
|
||||
service()
|
||||
}
|
||||
container.load(buildProviderModule());
|
||||
|
||||
// start the server
|
||||
let server = new InversifyExpressServer(container);
|
||||
|
||||
Reference in New Issue
Block a user