simple-boot-http-server
Advanced tools
Comparing version 1.0.2 to 1.0.3
/// <reference types="node" /> | ||
import { SimOption } from 'simple-boot-core/SimOption'; | ||
import { ConstructorType } from 'simple-boot-core/types/Types'; | ||
import { ServerOptions } from "http"; | ||
import { ServerOptions } from 'http'; | ||
import { Filter } from '../filters/Filter'; | ||
import { EndPoint } from '../endpoints/EndPoint'; | ||
import { Advice } from '../advices/Advice'; | ||
export declare type Listen = { | ||
@@ -14,3 +17,8 @@ port?: number; | ||
listen: Listen; | ||
filters?: (Filter | ConstructorType<Filter>)[]; | ||
requestEndPoints?: EndPoint[]; | ||
closeEndPoints?: EndPoint[]; | ||
errorEndPoints?: EndPoint[]; | ||
globalAdvice?: Advice; | ||
constructor(advice?: ConstructorType<any>[]); | ||
} |
@@ -26,2 +26,3 @@ "use strict"; | ||
_this.listen = { port: 8081 }; | ||
_this.filters = []; | ||
return _this; | ||
@@ -28,0 +29,0 @@ } |
{ | ||
"name": "simple-boot-http-server", | ||
"version": "1.0.2", | ||
"main": "SimpleHttpServerApplication.js", | ||
"version": "1.0.3", | ||
"main": "SimpleBootHttpServer.js", | ||
"license": "MIT", | ||
@@ -30,7 +30,2 @@ "description": "back end http server frameworks", | ||
}, | ||
"workspaces": [ | ||
"./", | ||
"examples/dev", | ||
"templates/http" | ||
], | ||
"jest": { | ||
@@ -55,6 +50,11 @@ "transform": { | ||
"build": "rm -rf dist && tsc --outDir dist --declarationDir dist", | ||
"build:watch": "rm -rf dist && tsc --watch --outDir dist --declarationDir dist", | ||
"npm-build": "rm -rf dist && tsc --outDir dist --declarationDir dist && cp package.json dist && cp README.MD dist", | ||
"npm-publish": "npm run npm-build && npm publish ./dist", | ||
"dev": "npm run dev --workspace=dev", | ||
"setting:root-dist": "rm -rf ../dist-simple-boot-http-server && mkdirp ../dist-simple-boot-http-server && cp package-root-dist.json ../dist-simple-boot-http-server/package.json", | ||
"tsc:root-dist": "npm run setting:root-dist && tsc --outDir ../dist-simple-boot-http-server --declarationDir ../dist-simple-boot-http-server", | ||
"tsc:watch:root-dist": "npm run setting:root-dist && tsc --outDir ../dist-simple-boot-http-server --declarationDir ../dist-simple-boot-http-server --watch --sourceMap true", | ||
"tsc": "tsc", | ||
"tsc:watch": "rm -rf ./dist && mkdir dist && cp package.json dist && tsc --watch --sourceMap true", | ||
"test": "jest --detectOpenHandles --forceExit" | ||
@@ -64,2 +64,3 @@ }, | ||
"@types/jest": "^26.0.23", | ||
"@types/mime-types": "^2.1.1", | ||
"@types/node": "^16.0.0", | ||
@@ -79,9 +80,10 @@ "@typescript-eslint/eslint-plugin": "^4.16.1", | ||
"tsconfig-paths": "^3.9.0", | ||
"typescript": "^4.2.3" | ||
"typescript": "^4.4.3" | ||
}, | ||
"dependencies": { | ||
"reflect-metadata": "^0.1.13", | ||
"rxjs": "^6.6.7", | ||
"simple-boot-core": "^1.0.22" | ||
"fast-json-patch": "^3.1.0", | ||
"mime-types": "^2.1.34", | ||
"simple-boot-front": "1.0.99" | ||
} | ||
} |
@@ -62,3 +62,3 @@ SIMPLE-BOOT-HTTP-SERVER | ||
res.writeHead(200, {'Content-Type': 'text/plain'}); | ||
res.write("11111111111111Hello World\n\n"); | ||
res.write("Hello World\n\n"); | ||
var text = 'Create Server test\n'; | ||
@@ -71,7 +71,5 @@ text += 'Server running at http://localhost:8081/ \n'; | ||
test() { | ||
console.log('---') | ||
} | ||
@After({property: 'receive'}) | ||
test2() { | ||
console.log('--22222-') | ||
} | ||
@@ -78,0 +76,0 @@ } |
import { SimpleApplication } from 'simple-boot-core/SimpleApplication'; | ||
import { HttpServerOption } from "./option/HttpServerOption"; | ||
import { HttpServerOption } from './option/HttpServerOption'; | ||
import { ConstructorType } from 'simple-boot-core/types/Types'; | ||
@@ -8,3 +8,3 @@ export declare class SimpleBootHttpServer extends SimpleApplication { | ||
constructor(rootRouter: ConstructorType<Object>, option?: HttpServerOption); | ||
run(): void; | ||
run(otherInstanceSim?: Map<ConstructorType<any>, any>): Promise<void>; | ||
} |
@@ -17,2 +17,38 @@ "use strict"; | ||
})(); | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -22,5 +58,8 @@ exports.SimpleBootHttpServer = void 0; | ||
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 RequestResponse_1 = require("./models/RequestResponse"); | ||
var MethodMapping_1 = require("./decorators/MethodMapping"); | ||
var HttpStatus_1 = require("./codes/HttpStatus"); | ||
var HttpHeaders_1 = require("./codes/HttpHeaders"); | ||
var Mimes_1 = require("./codes/Mimes"); | ||
var SimpleBootHttpServer = (function (_super) { | ||
@@ -35,26 +74,141 @@ __extends(SimpleBootHttpServer, _super); | ||
} | ||
SimpleBootHttpServer.prototype.run = function () { | ||
var _this = this; | ||
_super.prototype.run.call(this); | ||
var server = this.option.serverOption ? new http_1.Server(this.option.serverOption) : new http_1.Server(); | ||
server.on('request', function (req, res) { | ||
var _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, _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) { | ||
console.log('catch-->', it); | ||
SimpleBootHttpServer.prototype.run = function (otherInstanceSim) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var server; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
_super.prototype.run.call(this, otherInstanceSim); | ||
server = this.option.serverOption ? new http_1.Server(this.option.serverOption) : new http_1.Server(); | ||
server.on('request', function (req, res) { return __awaiter(_this, void 0, void 0, function () { | ||
var _i, _a, it_1, filter, _b, _c, it_2, execute, sw, rr_1, data, moduleInstance_1, methods, otherStorage_1, _d, _e, it_3, _f, e_1; | ||
var _this = this; | ||
var _g, _h, _j; | ||
return __generator(this, function (_k) { | ||
switch (_k.label) { | ||
case 0: | ||
_k.trys.push([0, 13, , 14]); | ||
if (this.option.requestEndPoints) { | ||
for (_i = 0, _a = this.option.requestEndPoints; _i < _a.length; _i++) { | ||
it_1 = _a[_i]; | ||
try { | ||
it_1.endPoint(req, res); | ||
} | ||
catch (e) { | ||
} | ||
} | ||
} | ||
if (!this.option.filters) return [3, 12]; | ||
filter = []; | ||
_b = 0, _c = this.option.filters; | ||
_k.label = 1; | ||
case 1: | ||
if (!(_b < _c.length)) return [3, 5]; | ||
it_2 = _c[_b]; | ||
execute = typeof it_2 === 'function' ? this.simstanceManager.getOrNewSim(it_2) : it_2; | ||
sw = true; | ||
if (!(execute === null || execute === void 0 ? void 0 : execute.before)) return [3, 3]; | ||
return [4, execute.before(req, res, this)]; | ||
case 2: | ||
sw = _k.sent(); | ||
filter.push({ filter: execute, sw: sw }); | ||
_k.label = 3; | ||
case 3: | ||
if (!sw) { | ||
return [3, 5]; | ||
} | ||
_k.label = 4; | ||
case 4: | ||
_b++; | ||
return [3, 1]; | ||
case 5: | ||
rr_1 = new RequestResponse_1.RequestResponse(req, res); | ||
if (!(!rr_1.res.finished || !rr_1.res.writableEnded)) return [3, 7]; | ||
return [4, this.routing(rr_1.reqIntent)]; | ||
case 6: | ||
data = _k.sent(); | ||
moduleInstance_1 = data.getModuleInstance(); | ||
if (moduleInstance_1) { | ||
methods = []; | ||
if ('GET' === rr_1.reqMethod()) { | ||
methods.push.apply(methods, (_g = (0, MethodMapping_1.getGETS)(moduleInstance_1)) !== null && _g !== void 0 ? _g : []); | ||
} | ||
else if ('POST' === rr_1.reqMethod()) { | ||
} | ||
otherStorage_1 = new Map(); | ||
otherStorage_1.set(RequestResponse_1.RequestResponse, rr_1); | ||
methods.forEach(function (it) { | ||
var _a, _b; | ||
var data = _this.simstanceManager.executeBindParameterSim({ target: moduleInstance_1, targetKey: it.propertyKey }, otherStorage_1); | ||
var status = (_a = it.config.resStatus) !== null && _a !== void 0 ? _a : HttpStatus_1.HttpStatus.Ok; | ||
var headers = it.config.resHeaders; | ||
rr_1.res.writeHead(status, headers); | ||
var contentType = Object.entries(headers !== null && headers !== void 0 ? headers : {}).find(function (_a) { | ||
var key = _a[0], value = _a[1]; | ||
return key.toLowerCase() === HttpHeaders_1.HttpHeaders.ContentType.toLowerCase(); | ||
}); | ||
if (((_b = contentType === null || contentType === void 0 ? void 0 : contentType[1]) !== null && _b !== void 0 ? _b : '').toLowerCase().indexOf(Mimes_1.Mimes.ApplicationJson.toLowerCase()) >= 0) { | ||
data = JSON.stringify(data); | ||
} | ||
rr_1.res.end(data); | ||
}); | ||
} | ||
_k.label = 7; | ||
case 7: | ||
_d = 0, _e = filter.reverse(); | ||
_k.label = 8; | ||
case 8: | ||
if (!(_d < _e.length)) return [3, 12]; | ||
it_3 = _e[_d]; | ||
_f = ((_h = it_3.filter) === null || _h === void 0 ? void 0 : _h.after); | ||
if (!_f) return [3, 10]; | ||
return [4, it_3.filter.after(req, res, this, it_3.sw)]; | ||
case 9: | ||
_f = !(_k.sent()); | ||
_k.label = 10; | ||
case 10: | ||
if (_f) { | ||
return [3, 12]; | ||
} | ||
_k.label = 11; | ||
case 11: | ||
_d++; | ||
return [3, 8]; | ||
case 12: return [3, 14]; | ||
case 13: | ||
e_1 = _k.sent(); | ||
(_j = this.option.globalAdvice) === null || _j === void 0 ? void 0 : _j.catch(e_1, req, res); | ||
return [3, 14]; | ||
case 14: | ||
res.on('close', function () { | ||
if (_this.option.closeEndPoints) { | ||
for (var _i = 0, _a = _this.option.closeEndPoints; _i < _a.length; _i++) { | ||
var it_4 = _a[_i]; | ||
try { | ||
it_4.endPoint(req, res); | ||
} | ||
catch (e) { | ||
} | ||
} | ||
} | ||
}); | ||
res.on('error', function () { | ||
if (_this.option.errorEndPoints) { | ||
for (var _i = 0, _a = _this.option.errorEndPoints; _i < _a.length; _i++) { | ||
var it_5 = _a[_i]; | ||
try { | ||
it_5.endPoint(req, res); | ||
} | ||
catch (e) { | ||
} | ||
} | ||
} | ||
}); | ||
return [2]; | ||
} | ||
}); | ||
}); }); | ||
server.listen(this.option.listen.port, this.option.listen.hostname, this.option.listen.backlog, this.option.listen.listeningListener); | ||
return [2]; | ||
}); | ||
}); | ||
server.listen(this.option.listen.port, this.option.listen.hostname, this.option.listen.backlog, this.option.listen.listeningListener); | ||
}; | ||
@@ -61,0 +215,0 @@ return SimpleBootHttpServer; |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
53590
32
975
4
17
95
1
2
+ Addedfast-json-patch@^3.1.0
+ Addedmime-types@^2.1.34
+ Addedsimple-boot-front@1.0.99
+ Addeddom-render@1.0.98(transitive)
+ Addedfast-json-patch@3.1.1(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedsimple-boot-front@1.0.99(transitive)
- Removedrxjs@^6.6.7
- Removedsimple-boot-core@^1.0.22
- Removedrxjs@6.6.7(transitive)
- Removedtslib@1.14.1(transitive)