Skip to content

Commit

Permalink
feat(nano-server): add token to connection
Browse files Browse the repository at this point in the history
  • Loading branch information
AliMD committed Aug 1, 2022
1 parent eae6523 commit 8677999
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/core/nano-server/src/nano-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ export class AlwatrConnection {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
readonly method = this.incomingMessage.method!.toUpperCase() as Methods;

readonly token = this._getToken();

readonly bodyPromise = this._getRequestBody();

protected _logger = createLogger(`alwatr-nano-server-connection`);
Expand Down Expand Up @@ -247,6 +249,15 @@ export class AlwatrConnection {
this.serverResponse.end();
}

protected _getToken(): string | void {
const auth = this.incomingMessage.headers.authorization?.split(' ');
if (auth != null && auth[0] === 'Bearer') {
return auth[1];
} else {
return;
}
}

protected async _getRequestBody(): Promise<string | void> {
// method must be POST or PUT
if (!(this.method === 'POST' || this.method === 'PUT')) {
Expand Down

0 comments on commit 8677999

Please sign in to comment.