ts-web-framework
v1.0.0
Published
A Web Server Framework ideal for create REST api's
Downloads
4
Maintainers
Readme
TypeScript Web Framework
Ideal to create Web Services.
Requeriments
- Nodejs 6+
- TypeScript 2.8+
Tested & Platform Support
- [x] Microsoft
- [x] Windows 7+
- [x] Azure AppService
- [x] Linux
- [x] Ubuntu
- [x] Fedora
- [x] CentOS
- [x] RedHat
- [x] Debian
- [x] AWS EC2
- [x] Arduino
- [x] Android Termux
- [x] OSX
Features
- [x] Controller
- [x] Annotations
- [x] @Uri
- [x] @Method
- [x] @Permission
- [x] @QueryString
- [x] Custom Middleware Controller
- [x] Default AuthController
- [ ] Default CorsController
- [ ] Default OAuth2Controller
- [ ] Lifecycle
- [x] beforeEnter
- [x] Promise support
- [x] main
- [x] Promise support
- [ ] afterEnter
- [ ] Promise support
- [x] beforeEnter
- [x] Easy Response
- [x] as Plain Text
- [x] as JSON
- [x]
200
- httpOk - [x]
201
- httpCreated - [x]
202
- httpAccepted - [x]
301
- httpRedirect - [x]
307
- httpRedirect - [x]
400
- httpBadRequest - [x]
401
- httpUnauthorized - [x]
403
- httpForbidden - [x]
404
- httpNotFound - [x]
405
- httpMethodNotAllowed
- [x] Annotations
- [x] Cors Settings
- [ ] Security
- [X] CSRF PreventionUsing CSurf
- [ ] Denial-Of-Service PreventionUsing DDDoS
- [x] Expect-CTUsing Helmet
- [x] Content Security PolicyUsing Helmet
- [x] DNS Prefetch ControlUsing Helmet
- [x] X-Frame-OptionsUsing Helmet
- [x] Hiden Powerd ByUsing Helmet
- [x] HTTP Public Key PinningUsing Helmet
- [x] HTTP Strict Transport SecurityUsing Helmet
- [x] X-Download-Options for IE8+Using Helmet
- [x] No CacheUsing Helmet
- [x] No SniffUsing Helmet
- [x] Referrer-PolicyUsing Helmet
- [X] XSS PreventionUsing Helmet
- [x] Basic CryptographyUsing crypto
- [x] AES-256-CTR Encrypt/Decrypt
- [ ] AES-256-GCM Encrypt/Decrypt
- [ ] AES-256-CBC Encrypt/Decrypt
- [x] HashingUsing crypto
- [x] SHA1
- [x] SHA256
- [x] SHA512
- [x] MD5
- [x] HMAC-SHA1
- [x] HMAC-SHA256
- [x] HMAC-SHA512
- [x] Checksum-MD5
- [x] Checksum-SHA1
- [x] Custom Middleware
- [X] SessionsUsing session
- [X] CookiesUsing cookie-session
- [x] Routes
Getting Started
Controllers
This framework only support one controller by uri
Create a new Controller
Annotations
@Route
Define URL for access to this controller
@Method
Define method to access to this controller
@Permission
Define permission to this controller. It can using with you own AuthController
Lifecycle
public
void|Promise<void>
main()
IMainController is like to "constructor".
If you overwride this function on you controller returning a promise, the framework will wait to receive some response from promise like resolve or reject to continue execution with afterEnter
method.
public
void|Promise<void>
beforeEnter()
Before execute main
If you overwride this function on you controller returning a promise, the framework will wait to receive some response from promise like resolve or reject to continue execution with main
method.
public
void|Promise<void>
afterEnter()
After execute main, this method will execute.
Example code
import {Route, Method, Permission, QueryString, Methods, Permissions, QueryStringTypes} from "../annotations/Annotations";
import {Controller} from "../core/Controller";
@Route("/my-own-url")
@Method(Methods.GET)
@Permission(Permissions.READ)
@QueryString("data", QueryStringTypes.JSON, false)
export class MyOwnController extends Controller {
public main () {
this.httpOk();
}
}
Middleware Controller
AuthController
import {Controller} from "../core/Controller";
export class AuthController extends Controller {
public beforeEnter ():Promise<any> {
return new Promise((resolve, reject) => {
if (!this.headers.exists("x-auth-token")) reject(new HttpUnauthorizedException());
resolve();
})
}
}
AuthController without Promise
import {Controller} from "../core/Controller";
export class AuthController extends Controller {
public beforeEnter ():void {
if (!("x-auth-controller" in this.request.headers)) {
throw new HttpUnauthorizedException();
}
}
}
Licence
MIT License
Copyright (c) 2018 Olaf Erlandsen C.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.