simple-boot-http-server
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "simple-boot-http-server", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"main": "SimpleHttpServerApplication.js", | ||
@@ -81,4 +81,4 @@ "license": "MIT", | ||
"rxjs": "^6.6.7", | ||
"simple-boot-core": "^1.0.7" | ||
"simple-boot-core": "^1.0.22" | ||
} | ||
} |
@@ -5,22 +5,58 @@ SIMPLE-BOOT-HTTP-SERVER | ||
```typescript | ||
const opiton = new HttpServerOption(AppRouter); | ||
new SimpleBootHttpServer(opiton).run(); | ||
// @ts-ignore | ||
import {SimpleBootHttpServer} from 'simple-boot-http-server/SimpleBootHttpServer'; | ||
import {HttpServerOption} from 'simple-boot-http-server/option/HttpServerOption'; | ||
import {AppRouter} from "./app/AppRouter"; | ||
const httpServerOption = new HttpServerOption(); | ||
new SimpleBootHttpServer(AppRouter, httpServerOption).run(); | ||
console.log('simple-boot-http-server start host:' + (httpServerOption.listen.hostname ?? 'localhost'), ' port:' + httpServerOption.listen.port); | ||
``` | ||
```typescript | ||
@Sim({}) | ||
export class AppRouter extends Router { | ||
'' = Index | ||
'/' = Index | ||
'/hello' = Hello | ||
import { Router, Sim } from "simple-boot-core/decorators/SimDecorator"; | ||
import {Hello} from "./features/hello"; | ||
import {Index} from "./features/Index"; | ||
import {UsersRouter} from "./features/users/UsersRouter"; | ||
import {Intent} from "simple-boot-core/intent/Intent"; | ||
import {ConstructorType} from "simple-boot-core/types/Types"; | ||
import {NotFound} from "src/app/features/errors/NotFound"; | ||
import { RouterAction } from 'simple-boot-core/route/RouterAction'; | ||
import { OnNotFoundReceiver } from 'simple-boot-http-server/lifecycle/OnNotFoundReceiver'; | ||
import { IncomingMessage, ServerResponse } from 'http'; | ||
constructor() { | ||
super('',[UsersRouter]); | ||
@Sim() | ||
@Router({ | ||
path: '', | ||
route: { | ||
'': Index, | ||
'/': Index, | ||
'/hello': Hello, | ||
'/hello/:zzz': Hello | ||
} | ||
}) | ||
export class AppRouter implements RouterAction, OnNotFoundReceiver{ | ||
constructor(private notFound: NotFound) { | ||
} | ||
canActivate(url: Intent, module: any): void { | ||
console.log('ii', url, module) | ||
} | ||
onNotFoundReceiver(req: IncomingMessage, res: ServerResponse): any { | ||
this.notFound.onReceive(req, res); | ||
} | ||
} | ||
``` | ||
```typescript | ||
@Sim({}) | ||
export class Index extends ReceiveModule { | ||
receive(req: IncomingMessage, res: ServerResponse) { | ||
console.log('request', req.url, req.method) | ||
import {IncomingMessage, ServerResponse} from "http"; | ||
import {Sim} from "simple-boot-core/decorators/SimDecorator"; | ||
import {After, Before} from "simple-boot-core/decorators/aop/AOPDecorator"; | ||
import { OnReceiver } from 'simple-boot-http-server/lifecycle/OnReceiver'; | ||
@Sim() | ||
export class Index implements OnReceiver { | ||
onReceive(req: IncomingMessage, res: ServerResponse) { | ||
res.writeHead(200, {'Content-Type': 'text/plain'}); | ||
@@ -32,4 +68,31 @@ res.write("11111111111111Hello World\n\n"); | ||
} | ||
@Before({property: 'receive'}) | ||
test() { | ||
console.log('---') | ||
} | ||
@After({property: 'receive'}) | ||
test2() { | ||
console.log('--22222-') | ||
} | ||
} | ||
``` | ||
```typescript | ||
import {IncomingMessage, ServerResponse} from "http"; | ||
import {Sim} from "simple-boot-core/decorators/SimDecorator"; | ||
import {RouterManager} from "simple-boot-core/route/RouterManager"; | ||
import { OnReceiver } from 'simple-boot-http-server/lifecycle/OnReceiver'; | ||
@Sim({}) | ||
export class Hello implements OnReceiver{ | ||
constructor(private routerManager: RouterManager) { | ||
} | ||
onReceive(req: IncomingMessage, res: ServerResponse) { | ||
res.setHeader('Content-Type', 'application/json'); | ||
res.end(JSON.stringify({ a: 1 })); | ||
} | ||
} | ||
``` |
import { SimpleApplication } from 'simple-boot-core/SimpleApplication'; | ||
import { HttpServerOption } from "./option/HttpServerOption"; | ||
import { HttpRouter } from "./router/HttpRouter"; | ||
import { ConstructorType } from "simple-boot-core/types/Types"; | ||
import { ConstructorType } from 'simple-boot-core/types/Types'; | ||
export declare class SimpleBootHttpServer extends SimpleApplication { | ||
rootRouter: ConstructorType<HttpRouter>; | ||
rootRouter: ConstructorType<Object>; | ||
option: HttpServerOption; | ||
constructor(rootRouter: ConstructorType<HttpRouter>, option: HttpServerOption); | ||
constructor(rootRouter: ConstructorType<Object>, option?: HttpServerOption); | ||
run(): void; | ||
} |
@@ -20,7 +20,10 @@ "use strict"; | ||
var SimpleApplication_1 = require("simple-boot-core/SimpleApplication"); | ||
var HttpServerOption_1 = require("./option/HttpServerOption"); | ||
var Intent_1 = require("simple-boot-core/intent/Intent"); | ||
var url_1 = require("url"); | ||
var http_1 = require("http"); | ||
var Intent_1 = require("simple-boot-core/intent/Intent"); | ||
var SimpleBootHttpServer = (function (_super) { | ||
__extends(SimpleBootHttpServer, _super); | ||
function SimpleBootHttpServer(rootRouter, option) { | ||
if (option === void 0) { option = new HttpServerOption_1.HttpServerOption(); } | ||
var _this = _super.call(this, rootRouter, option) || this; | ||
@@ -37,6 +40,15 @@ _this.rootRouter = rootRouter; | ||
var _a; | ||
var intent = new Intent_1.Intent((_a = req.url) !== null && _a !== void 0 ? _a : ''); | ||
var url = new url_1.URL(req.url, 'http://' + req.headers.host); | ||
var intent = new Intent_1.Intent((_a = req.url) !== null && _a !== void 0 ? _a : '', url); | ||
_this.routing(intent).then(function (it) { | ||
var _a; | ||
(_a = it.getModuleInstance()) === null || _a === void 0 ? void 0 : _a.receive(req, res); | ||
var _a, _b, _c; | ||
console.log('routring-->', it); | ||
var moduleInstance = it.getModuleInstance(); | ||
if (moduleInstance) { | ||
(_a = moduleInstance === null || moduleInstance === void 0 ? void 0 : moduleInstance.onReceive) === null || _a === void 0 ? void 0 : _a.call(moduleInstance, req, res); | ||
} | ||
else { | ||
(_c = (_b = it.router) === null || _b === void 0 ? void 0 : _b.onNotFoundReceiver) === null || _c === void 0 ? void 0 : _c.call(_b, req, res); | ||
} | ||
res.end(); | ||
}).catch(function (it) { | ||
@@ -43,0 +55,0 @@ console.log('catch-->', it); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
97
1
11195
10
128
Updatedsimple-boot-core@^1.0.22