simple-boot-http-server
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -400,3 +400,3 @@ "use strict"; | ||
if (encoding === void 0) { encoding = 'utf8'; } | ||
return this.resWrite(this.resWrite(JSON.stringify(chunk), encoding)); | ||
return this.resWrite(JSON.stringify(chunk), encoding); | ||
}; | ||
@@ -403,0 +403,0 @@ RequestResponse.prototype.resSetHeader = function (key, value) { |
/// <reference types="node" /> | ||
import { SimOption } from 'simple-boot-core/SimOption'; | ||
import { ConstructorType } from 'simple-boot-core/types/Types'; | ||
import { ServerOptions } from 'http'; | ||
import { Server, ServerOptions } from 'http'; | ||
import { Filter } from '../filters/Filter'; | ||
@@ -10,10 +10,16 @@ import { EndPoint } from '../endpoints/EndPoint'; | ||
export declare type Listen = { | ||
port: number; | ||
port?: number; | ||
hostname?: string; | ||
backlog?: number; | ||
listeningListener?: (server: SimpleBootHttpServer) => void; | ||
listeningListener?: (server: SimpleBootHttpServer, httpServer: Server) => void; | ||
}; | ||
export interface ListenData extends Listen { | ||
port: number; | ||
hostname: string; | ||
} | ||
export declare class HttpServerOption extends SimOption { | ||
static readonly DEFAULT_PORT = 8081; | ||
static readonly DEFAULT_HOSTNAME = "127.0.0.1"; | ||
serverOption?: ServerOptions; | ||
listen: Listen; | ||
listen: ListenData; | ||
filters?: (Filter | ConstructorType<Filter>)[]; | ||
@@ -20,0 +26,0 @@ requestEndPoints?: (EndPoint | ConstructorType<EndPoint>)[]; |
@@ -23,7 +23,7 @@ "use strict"; | ||
function HttpServerOption(_a, advice) { | ||
var _b = _a === void 0 ? {} : _a, serverOption = _b.serverOption, _c = _b.listen, listen = _c === void 0 ? { port: 8081 } : _c, filters = _b.filters, requestEndPoints = _b.requestEndPoints, closeEndPoints = _b.closeEndPoints, errorEndPoints = _b.errorEndPoints, globalAdvice = _b.globalAdvice, noSuchRouteEndPointMappingThrow = _b.noSuchRouteEndPointMappingThrow; | ||
var _b = _a === void 0 ? {} : _a, serverOption = _b.serverOption, listen = _b.listen, filters = _b.filters, requestEndPoints = _b.requestEndPoints, closeEndPoints = _b.closeEndPoints, errorEndPoints = _b.errorEndPoints, globalAdvice = _b.globalAdvice, noSuchRouteEndPointMappingThrow = _b.noSuchRouteEndPointMappingThrow; | ||
if (advice === void 0) { advice = []; } | ||
var _this = _super.call(this, advice) || this; | ||
_this.serverOption = serverOption; | ||
_this.listen = listen; | ||
_this.listen = Object.assign({ port: HttpServerOption.DEFAULT_PORT, hostname: HttpServerOption.DEFAULT_HOSTNAME }, listen); | ||
_this.filters = filters; | ||
@@ -37,4 +37,6 @@ _this.requestEndPoints = requestEndPoints; | ||
} | ||
HttpServerOption.DEFAULT_PORT = 8081; | ||
HttpServerOption.DEFAULT_HOSTNAME = '127.0.0.1'; | ||
return HttpServerOption; | ||
}(SimOption_1.SimOption)); | ||
exports.HttpServerOption = HttpServerOption; |
{ | ||
"name": "simple-boot-http-server", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"main": "SimpleBootHttpServer.js", | ||
@@ -83,4 +83,4 @@ "license": "MIT", | ||
"mime-types": "^2.1.34", | ||
"simple-boot-core": "^1.0.30" | ||
"simple-boot-core": "^1.0.32" | ||
} | ||
} |
@@ -24,2 +24,4 @@ SIMPLE-BOOT-HTTP-SERVER | ||
```typescript | ||
import {HttpServerOption} from 'simple-boot-http-server/option/HttpServerOption'; | ||
import {SimpleBootHttpServer} from 'simple-boot-http-server'; | ||
import {Sim} from 'simple-boot-core/decorators/SimDecorator'; | ||
@@ -40,5 +42,14 @@ import {Route, Router} from 'simple-boot-core/decorators/route/Router'; | ||
} | ||
new SimpleBootHttpServer(AppRouter).run().then(it => { | ||
console.log('server starting..', it.option.listen) | ||
}) | ||
const httpServerOption = new HttpServerOption({ | ||
listen: { | ||
listeningListener: (server, httpServer) => { | ||
console.log('server on', httpServer.address()); | ||
} | ||
} | ||
}); | ||
const app = new SimpleBootHttpServer(AppRouter, httpServerOption); | ||
app.run(); | ||
// 💥 GET / | ||
@@ -112,5 +123,12 @@ // {"name": "visualkhh"} | ||
const httpServerOption = new HttpServerOption({ | ||
filters: [new FirstFilter()] | ||
}) | ||
new SimpleBootHttpServer(AppRouter, httpServerOption).run(); | ||
filters: [new FirstFilter()], | ||
listen: { | ||
listeningListener: (server, httpServer) => { | ||
console.log('server on', httpServer.address()); | ||
} | ||
} | ||
}); | ||
const app = new SimpleBootHttpServer(AppRouter, httpServerOption); | ||
app.run(); | ||
// 💥 CALL | ||
@@ -136,5 +154,12 @@ // filter before | ||
globalAdvice: Advice, | ||
noSuchRouteEndPointMappingThrow: rr => new NotFoundError() | ||
noSuchRouteEndPointMappingThrow: rr => new NotFoundError(), | ||
listen: { | ||
listeningListener: (server, httpServer) => { | ||
console.log('server on', httpServer.address()); | ||
} | ||
} | ||
}); | ||
new SimpleBootHttpServer(AppRouter, httpServerOption).run(); | ||
const app = new SimpleBootHttpServer(AppRouter, httpServerOption); | ||
app.run(); | ||
// 💥 CALL | ||
@@ -161,4 +186,11 @@ // exception---> NotFound | ||
closeEndPoints: [ErrorEndPoint], | ||
listen: { | ||
listeningListener: (server, httpServer) => { | ||
console.log('server on', httpServer.address()); | ||
} | ||
} | ||
}); | ||
new SimpleBootHttpServer(AppRouter, httpServerOption).run(); | ||
const app = new SimpleBootHttpServer(AppRouter, httpServerOption); | ||
app.run(); | ||
// 💥 normal CALL | ||
@@ -165,0 +197,0 @@ // close request response |
@@ -0,10 +1,13 @@ | ||
/// <reference types="node" /> | ||
import { SimpleApplication } from 'simple-boot-core/SimpleApplication'; | ||
import { HttpServerOption } from './option/HttpServerOption'; | ||
import { ConstructorType } from 'simple-boot-core/types/Types'; | ||
import { Server } from 'http'; | ||
export declare class SimpleBootHttpServer extends SimpleApplication { | ||
rootRouter: ConstructorType<Object>; | ||
option: HttpServerOption; | ||
server?: Server; | ||
constructor(rootRouter: ConstructorType<Object>, option?: HttpServerOption); | ||
run(otherInstanceSim?: Map<ConstructorType<any>, any>): void; | ||
run(otherInstanceSim?: Map<ConstructorType<any>, any>): import("simple-boot-core/simstance/SimstanceManager").SimstanceManager; | ||
private startServer; | ||
} |
@@ -97,3 +97,3 @@ "use strict"; | ||
var _a, _b, _c, _d; | ||
_super.prototype.run.call(this, otherInstanceSim); | ||
var simstanceManager = _super.prototype.run.call(this, otherInstanceSim); | ||
var targets = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], (_a = this.option.closeEndPoints) !== null && _a !== void 0 ? _a : [], true), (_b = this.option.errorEndPoints) !== null && _b !== void 0 ? _b : [], true), (_c = this.option.requestEndPoints) !== null && _c !== void 0 ? _c : [], true), (_d = this.option.filters) !== null && _d !== void 0 ? _d : [], true); | ||
@@ -103,2 +103,3 @@ Promise.all(targets.map(function (it) { return (typeof it === 'function' ? _this.simstanceManager.getOrNewSim(it) : it); }).map(function (it) { return it.onInit(_this); })).then(function (it) { | ||
}); | ||
return simstanceManager; | ||
}; | ||
@@ -108,2 +109,3 @@ SimpleBootHttpServer.prototype.startServer = function () { | ||
var server = this.option.serverOption ? new http_1.Server(this.option.serverOption) : new http_1.Server(); | ||
this.server = server; | ||
server.on('request', function (req, res) { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -239,3 +241,5 @@ var rr, otherStorage, _i, _a, it_1, execute, filter, i, it_2, execute, sw, routerModule, moduleInstance_1, methods, map, it_3, paramTypes, injects, validIndexs, isJson, isFormUrl, siturationContainers, data_1, inValid, data_2, inValid, _b, paramTypes_1, paramType, _c, _d, _e, _f, _g, _h, data, execute, status, headers, _j, _k, it_4, _l, e_1, execute, target; | ||
if (routerModule.propertyKeys) { | ||
map = (_o = routerModule.propertyKeys) === null || _o === void 0 ? void 0 : _o.map(function (it) { return { propertyKey: it, config: (0, MethodMapping_1.getUrlMapping)(moduleInstance_1, it) }; }); | ||
map = (_o = routerModule.propertyKeys) === null || _o === void 0 ? void 0 : _o.map(function (it) { | ||
return { propertyKey: it, config: (0, MethodMapping_1.getUrlMapping)(moduleInstance_1, it) }; | ||
}); | ||
methods.push.apply(methods, (map !== null && map !== void 0 ? map : [])); | ||
@@ -426,3 +430,3 @@ } | ||
var _a, _b; | ||
(_b = (_a = _this.option.listen).listeningListener) === null || _b === void 0 ? void 0 : _b.call(_a, _this); | ||
(_b = (_a = _this.option.listen).listeningListener) === null || _b === void 0 ? void 0 : _b.call(_a, _this, server); | ||
}); | ||
@@ -429,0 +433,0 @@ }; |
129221
2485
196
Updatedsimple-boot-core@^1.0.32