1.2.97 • Published 4 years ago

syncup-express-routing v1.2.97

Weekly downloads
107
License
ISC
Repository
gitlab
Last release
4 years ago

ExpressDecorators

This project is trying to achieve to provide Angular-like annotations for using the express framework.

ToDo

  • ErrorHandling

Featurelist

This is a list of all features that will be implemented.

Dependency Injection

  • Mark a class as @Injectable() to make it accessable to any other managed class.
  • A managed class can be anything, controllers, middlewares or even the server.
  • If a class is not a anything of the above three, it needs to be defined as a provider in the module it is needed.
  • If an injectable class has dependencies on other injectable classes, it will be inject using the constructor.
@Injectable()
export class ExampleInjectableService {

    public getSomeData(): Observable<Data> {
        return ["Hello World"];
    }
}

Modules

  • A module should be able to define everything related to the application (Controllers, Middlewares).
  • A module defines everything all of its controllers and middlewares need.

Example:

@Module({
    controllers: [
        ExampleController
    ],
    middlewares: [
        ExampleMiddleware
    ],
    providers: [
        ExampleInjectableService
    ]
})
export class ExampleModule {}

Server

  • The server should be able to mount 1 to n modules.
  • It defines on which port it runs.
  • Middlewares should be able to be attached.
@Server({
    port: 8080,
    middlewares: [
        BodyParser,
        CORS
    ],
    imports: [
        ExampleModule
    ],
    providers: [
        AuthenticationService
    ]
})
export class ExampleServer {}

Controller

  • A controller can define functions for a specific routes that handle the request.
  • Middlewares should be able to be applied to the controller or controller function.
  • Mark functions as Get, Post, Put or Delete to make them resolve to a URI.
  • A controller function should be able to have middlewares.
@Controller({
    path: '/exmaplepath',
    middlewares: [
        Authorized
    ]
})
export class ExampleController {

    constructor(private exampleInjectableService: ExampleInjectableService) {}

    @Get({
        path: '/{id}',
        middlewares: []
    })
    public getExampleData(@ResponseParam() response: Response, @PathVariable id: number) {
        this.exampleInjectableService.getExampleData().subscribe(data => response.send(data));
    }
}

Middleware

  • A middleware should intercept a request to a resource and decide to weather or not the request shall be passed on.
@Middleware()
export class ExampleMiddleware {

    constructor(private authorizationService: AuthorizationService) {}

    public onRequest(@ResponseParam response: Response, @Next next: NextFunction) {
        this.authorizationService.isAuthorized(token).subscribe(authorized => {
            if (authorized) {
                next()
            } else {
                response.sendStatus(401);
            }
        });
    }
}

App

@App({
    bootstrap: [ExampleServer]
})
export class ExampleApp extends ExpressApp {}

const exampleApp = new ExampleApp()
exampleApp.start((server) => {
    console.log("Application is running on port: " + server.port);
}, (error) => {
    console.log("Error: Could not start application.", error);
})
1.2.96

4 years ago

1.2.97

4 years ago

1.2.95

4 years ago

1.2.92

4 years ago

1.2.93

4 years ago

1.2.94

4 years ago

1.2.91

4 years ago

1.2.85

4 years ago

1.2.86

4 years ago

1.2.83

4 years ago

1.2.84

4 years ago

1.2.89

4 years ago

1.2.87

4 years ago

1.2.88

4 years ago

1.2.90

4 years ago

1.2.81

4 years ago

1.2.82

4 years ago

1.2.80

4 years ago

1.2.67

4 years ago

1.2.68

4 years ago

1.2.69

4 years ago

1.2.70

4 years ago

1.2.71

4 years ago

1.2.74

4 years ago

1.2.75

4 years ago

1.2.72

4 years ago

1.2.73

4 years ago

1.2.78

4 years ago

1.2.79

4 years ago

1.2.76

4 years ago

1.2.77

4 years ago

1.2.60

4 years ago

1.2.63

4 years ago

1.2.64

4 years ago

1.2.61

4 years ago

1.2.62

4 years ago

1.2.65

4 years ago

1.2.66

4 years ago

1.2.58

4 years ago

1.2.59

4 years ago

1.2.56

4 years ago

1.2.57

4 years ago

1.2.55

4 years ago

1.2.54

4 years ago

1.2.53

4 years ago

1.2.52

4 years ago

1.2.51

5 years ago

1.2.49

6 years ago

1.2.50

6 years ago

1.2.48

6 years ago

1.2.47

6 years ago

1.2.46

6 years ago

1.2.45

6 years ago

1.2.44

6 years ago

1.2.43

6 years ago

1.2.42

6 years ago

1.2.41

6 years ago

1.2.40

6 years ago

1.2.39

6 years ago

1.2.38

6 years ago

1.2.37

6 years ago

1.2.36

6 years ago

1.2.35

6 years ago

1.2.34

6 years ago

1.2.33

6 years ago

1.2.32

6 years ago

1.2.31

6 years ago

1.2.30

6 years ago

1.2.29

6 years ago

1.2.28

6 years ago

1.2.27

6 years ago

1.2.26

6 years ago

1.2.25

6 years ago

1.2.24

6 years ago

1.2.23

6 years ago

1.2.22

6 years ago

1.2.21

6 years ago

1.2.20

6 years ago

1.2.19

6 years ago

1.2.18

6 years ago

1.2.17

6 years ago

1.2.16

6 years ago

1.2.15

6 years ago

1.2.14

6 years ago

1.2.13

6 years ago

1.2.12

6 years ago

1.2.11

6 years ago

1.2.10

6 years ago

1.2.9

6 years ago

1.2.8

6 years ago

1.2.7

6 years ago

1.2.6

6 years ago

1.2.5

6 years ago

1.2.4

6 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.38

6 years ago

1.1.37

6 years ago

1.1.36

6 years ago

1.1.35

6 years ago

1.1.34

6 years ago

1.1.33

6 years ago

1.1.32

6 years ago

1.1.31

6 years ago

1.1.30

6 years ago

1.1.29

6 years ago

1.1.28

6 years ago

1.1.27

6 years ago

1.1.26

6 years ago

1.1.25

6 years ago

1.1.24

6 years ago

1.1.23

6 years ago

1.1.22

6 years ago

1.1.21

6 years ago

1.1.20

6 years ago

1.1.19

6 years ago

1.1.18

6 years ago

1.1.17

6 years ago

1.1.16

6 years ago

1.1.15

6 years ago

1.1.14

6 years ago

1.1.13

6 years ago

1.1.12

6 years ago

1.1.11

6 years ago

1.1.10

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2-a

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago