Skip to content

Commit

Permalink
fix: HttpRequestInfo types + add credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
juneil committed May 28, 2018
1 parent a2b1c07 commit 749bf24
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/extensions/http-server/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ export class LifecycleManager {
static routeLifecycle(server: Server, routes: CoreRoute[]): void {

server.ext(<any>LifecycleEventsEnum.OnPreAuth.toString(),
(request: Request, reply: ReplyWithContinue) =>
this.instantiateRoute(routes, request, reply)
.subscribe(
_ => reply.continue(),
_ => errorHandler(_)
)
(request: Request, reply: ReplyWithContinue) =>
this.eventHandler(LifecycleHooksEnum.OnPreAuth, routes, request, reply)
.subscribe(
_ => reply.continue(),
_ => errorHandler(_)
)
);

server.ext(<any>LifecycleEventsEnum.OnPostAuth.toString(),
(request: Request, reply: ReplyWithContinue) =>
this.eventHandler(LifecycleHooksEnum.OnPostAuth, routes, request, reply)
this.instantiateRoute(routes, request, reply)
.subscribe(
_ => reply.continue(),
_ => errorHandler(_)
Expand Down Expand Up @@ -84,7 +84,7 @@ export class LifecycleManager {
)
.do(_ => request['_hapinessRoute'] = _.instance)
.defaultIfEmpty(null)
.flatMap(_ => this.eventHandler(LifecycleHooksEnum.OnPreAuth, routes, request, reply))
.flatMap(_ => this.eventHandler(LifecycleHooksEnum.OnPostAuth, routes, request, reply))
}

/**
Expand Down
10 changes: 9 additions & 1 deletion src/extensions/http-server/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ interface InternalType {
token: Type<any>;
}

export class HttpRequestInfo {}
export class HttpRequestInfo {
query: {[key: string]: string};
params: {[key: string]: string};
headers: {[key: string]: string};
payload: {[key: string]: string};
credentials: {[key: string]: string};
id: string;
}

export class RouteBuilder {

Expand Down Expand Up @@ -54,6 +61,7 @@ export class RouteBuilder {
params: Object.assign({}, request.params),
headers: Object.assign({}, request.headers),
payload: Object.assign({}, request.payload),
credentials: Object.assign({}, request.auth.credentials),
id: request.id
}))
.map(_ => ({ provide: HttpRequestInfo, useValue: _ }))
Expand Down
2 changes: 1 addition & 1 deletion test/integration/core.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { suite, test } from 'mocha-typescript';
import { Hapiness, HapinessModule, OnStart, OnRegister, Lib, Injectable, ExtensionShutdownPriority } from '../../src/core';
import * as unit from 'unit.js';
import { Observable } from 'rxjs';
import { Observable } from 'rxjs/Observable';

@suite('Integration - Core')
export class ModuleTestSuite {
Expand Down

0 comments on commit 749bf24

Please sign in to comment.