This commit is contained in:
2020-01-07 10:00:32 +08:00
parent e078e7d503
commit f13e98568b
11 changed files with 65 additions and 59 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@cc-server/core",
"version": "0.6.9",
"version": "0.7.0",
"description": "> TODO: description",
"author": "MiaoWoo <admin@yumc.pw>",
"homepage": "https://github.com/502647092/cc-server-parent#readme",
@@ -21,27 +21,27 @@
"url": "git+https://github.com/502647092/cc-server-parent.git"
},
"dependencies": {
"@cc-server/binding": "^0.6.9",
"@cc-server/db-mongo": "^0.6.9",
"@cc-server/ioc": "^0.6.9",
"@cc-server/ws": "^0.6.9",
"@cc-server/binding": "^0.7.0",
"@cc-server/db-mongo": "^0.7.0",
"@cc-server/ioc": "^0.7.0",
"@cc-server/ws": "^0.7.0",
"body-parser": "^1.19.0",
"globby": "^9.2.0",
"globby": "^10.0.2",
"inversify": "^5.0.1",
"inversify-express-utils": "^6.3.2",
"prettyjson": "^1.2.1",
"socket.io": "^2.2.0"
"socket.io": "^2.3.0"
},
"devDependencies": {
"@types/body-parser": "^1.17.0",
"@types/express": "^4.17.0",
"@types/body-parser": "^1.17.1",
"@types/express": "4.17.0",
"@types/prettyjson": "^0.0.29",
"@types/socket.io": "^2.1.2",
"mocha": "^6.1.4",
"rimraf": "^2.6.3",
"ts-node": "^8.2.0",
"ts-node-dev": "^1.0.0-pre.40",
"typescript": "^3.5.1"
"@types/socket.io": "^2.1.4",
"mocha": "^7.0.0",
"rimraf": "^3.0.0",
"ts-node": "^8.5.4",
"ts-node-dev": "^1.0.0-pre.44",
"typescript": "^3.7.4"
},
"gitHead": "7d84393a3cb6be6be9ed51d71f12677d2d7d0728"
}

View File

@@ -1,6 +1,7 @@
import 'reflect-metadata';
import * as fs from 'fs';
import * as http from 'http';
import * as path from 'path';
import * as globby from "globby";
import * as express from "express";
import * as prettyjson from "prettyjson";
@@ -104,11 +105,18 @@ export class CcServerBoot {
return this;
}
public scan(path: fs.PathLike) {
let files = fs.readdirSync(path);
for (const file of files) {
public scan(scanDir: string) {
let files = fs.readdirSync(scanDir);
for (let file of files) {
let moduleDir = path.join(scanDir, file)
let stat = fs.statSync(moduleDir);
if (stat.isDirectory()) {
this.scan(moduleDir)
} else if (stat.isFile() && (file.endsWith('.js') || file.endsWith('.ts'))) {
require(moduleDir);
}
}
return this;
}
public build() {

View File

@@ -1,17 +1,14 @@
import { CcServerBoot, express } from './index'
import './function/http';
import './function/websocket';
import { CcServerBoot } from './index'
import { DBClient } from '@cc-server/db';
import { MongoClient } from 'mongodb';
import { MongoCollection } from '@cc-server/db-mongo';
let boot = new CcServerBoot().static('public');
let boot = new CcServerBoot().scan(__dirname + '/function');
MongoClient.connect("mongodb://192.168.2.5:27017", { useNewUrlParser: true }, (error, client) => {
if (error) {
console.log(error)
} else {
boot.container.bind(DBClient).toConstantValue(new MongoCollection(client.db("faas").collection("users"))).whenTargetNamed("users")
boot.build().listen();
boot.start();
}
})