ts-web-framework v1.0.0
TypeScript Web Framework
Ideal to create Web Services.
Requeriments
- Nodejs 6+
- TypeScript 2.8+
Tested & Platform Support
- Microsoft
- Windows 7+
- Azure AppService
- Linux
- Ubuntu
- Fedora
- CentOS
- RedHat
- Debian
- AWS EC2
- Arduino
- Android Termux
- OSX
Features
- Controller
- Annotations
- @Uri
- @Method
- @Permission
- @QueryString
- Custom Middleware Controller
- Default AuthController
- Default CorsController
- Default OAuth2Controller
- Lifecycle
- beforeEnter
- Promise support
- main
- Promise support
- afterEnter
- Promise support
- beforeEnter
- Easy Response
- as Plain Text
- as JSON
200
- httpOk201
- httpCreated202
- httpAccepted301
- httpRedirect307
- httpRedirect400
- httpBadRequest401
- httpUnauthorized403
- httpForbidden404
- httpNotFound405
- httpMethodNotAllowed
- Annotations
- Cors Settings
- Security
- CSRF PreventionUsing CSurf
- Denial-Of-Service PreventionUsing DDDoS
- Expect-CTUsing Helmet
- Content Security PolicyUsing Helmet
- DNS Prefetch ControlUsing Helmet
- X-Frame-OptionsUsing Helmet
- Hiden Powerd ByUsing Helmet
- HTTP Public Key PinningUsing Helmet
- HTTP Strict Transport SecurityUsing Helmet
- X-Download-Options for IE8+Using Helmet
- No CacheUsing Helmet
- No SniffUsing Helmet
- Referrer-PolicyUsing Helmet
- XSS PreventionUsing Helmet
- Basic CryptographyUsing crypto
- AES-256-CTR Encrypt/Decrypt
- AES-256-GCM Encrypt/Decrypt
- AES-256-CBC Encrypt/Decrypt
- HashingUsing crypto
- SHA1
- SHA256
- SHA512
- MD5
- HMAC-SHA1
- HMAC-SHA256
- HMAC-SHA512
- Checksum-MD5
- Checksum-SHA1
- Custom Middleware
- SessionsUsing session
- CookiesUsing cookie-session
- 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.
6 years ago