Init Project...

This commit is contained in:
2019-06-10 18:56:29 +08:00
commit 1746ffa773
25 changed files with 358 additions and 0 deletions

4
packages/cc-server-core/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
/node_modules
/dist
/package-lock.json
/yarn.lock

View File

@@ -0,0 +1,11 @@
# `cc-server-core`
> TODO: description
## Usage
```
const ccServerCore = require('cc-server-core');
// TODO: DEMONSTRATE API
```

View File

@@ -0,0 +1,29 @@
{
"name": "cc-server-core",
"version": "0.0.1",
"description": "> TODO: description",
"author": "MiaoWoo <admin@yumc.pw>",
"homepage": "https://faas.yumc.pw",
"license": "ISC",
"main": "dist/index.js",
"publishConfig": {
"registry": "https://repo.yumc.pw/repository/npm-hosted/"
},
"scripts": {
"dev": "npx ts-node src/index.ts",
"test": "echo \"Error: run tests from root\" && exit 1"
},
"dependencies": {
"body-parser": "^1.19.0",
"cc-server-db-mongo": "^0.0.1",
"cc-server-ioc": "^0.0.1",
"inversify": "^5.0.1",
"inversify-express-utils": "^6.3.2",
"reflect-metadata": "^0.1.13",
"typescript": "^3.5.1"
},
"devDependencies": {
"@types/body-parser": "^1.17.0",
"ts-node": "^8.2.0"
}
}

View File

@@ -0,0 +1,22 @@
import {
controller, httpGet, httpPost, httpPut, httpDelete
} from 'inversify-express-utils';
import { inject } from 'inversify';
import { MongoDBClient } from 'cc-server-db-mongo'
@controller('/')
export class UserController {
constructor(
@inject(MongoDBClient) private MongoDBClient: MongoDBClient
) { }
@httpGet('/')
public async getUsers(): Promise<any[]> {
return []
}
@httpPost('/')
public async newUser(): Promise<any> {
return {}
}
}

View File

@@ -0,0 +1,22 @@
{
"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"
]
}

View File

@@ -0,0 +1,32 @@
import 'reflect-metadata';
import { InversifyExpressServer } from 'inversify-express-utils';
import { Container } from 'inversify';
import * as bodyParser from 'body-parser';
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()
}
// start the server
let server = new InversifyExpressServer(container);
server.setConfig((app) => {
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.use(bodyParser.raw())
});
let serverInstance = server.build();
serverInstance.listen(80);
console.log('Server started on port 80 :)');

View File

@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": "src",
"outDir": "dist"
}
}