Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

simple-boot-http-server

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-boot-http-server - npm Package Compare versions

Comparing version
1.0.1
to
1.0.2
+5
lifecycle/OnNotFoundReceiver.d.ts
/// <reference types="node" />
import { IncomingMessage, ServerResponse } from "http";
export interface OnNotFoundReceiver {
onNotFoundReceiver(req: IncomingMessage, res: ServerResponse): any;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/// <reference types="node" />
import { IncomingMessage, ServerResponse } from "http";
export interface OnReceiver {
onReceive(req: IncomingMessage, res: ServerResponse): any;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
+2
-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"
}
}
+76
-13

@@ -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);

/// <reference types="node" />
import { Module } from "simple-boot-core/module/Module";
import { IncomingMessage, ServerResponse } from "http";
export declare abstract class HttpModule extends Module {
receive(req: IncomingMessage, res: ServerResponse): void;
}
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.HttpModule = void 0;
var Module_1 = require("simple-boot-core/module/Module");
var HttpModule = (function (_super) {
__extends(HttpModule, _super);
function HttpModule() {
return _super !== null && _super.apply(this, arguments) || this;
}
HttpModule.prototype.receive = function (req, res) {
};
return HttpModule;
}(Module_1.Module));
exports.HttpModule = HttpModule;
import { ConstructorType } from 'simple-boot-core/types/Types';
import { Router } from "simple-boot-core/route/Router";
export declare class HttpRouter extends Router {
path: string;
childs: ConstructorType<HttpRouter>[];
constructor(path?: string, childs?: ConstructorType<HttpRouter>[]);
}
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.HttpRouter = void 0;
var Router_1 = require("simple-boot-core/route/Router");
var HttpRouter = (function (_super) {
__extends(HttpRouter, _super);
function HttpRouter(path, childs) {
if (path === void 0) { path = ''; }
if (childs === void 0) { childs = []; }
var _this = _super.call(this, path, childs) || this;
_this.path = path;
_this.childs = childs;
return _this;
}
return HttpRouter;
}(Router_1.Router));
exports.HttpRouter = HttpRouter;
import { HttpRouter } from './HttpRouter';
import { HttpModule } from "../module/HttpModule";
export declare class RouterModule {
router?: HttpRouter | undefined;
module?: HttpModule | undefined;
constructor(router?: HttpRouter | undefined, module?: HttpModule | undefined);
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RouterModule = void 0;
var RouterModule = (function () {
function RouterModule(router, module) {
this.router = router;
this.module = module;
}
return RouterModule;
}());
exports.RouterModule = RouterModule;