Skip to content

Commit

Permalink
feat: refactoring dev proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
fletcherist committed Jul 13, 2018
1 parent d853700 commit cece2bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/alice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ export default class Alice {
* @param {Function} sendResponse — Express res function while listening on port.
*/
public async handleRequestBody(req, sendResponse) {
const requestedCommandName = selectCommand(req)

/* clear old sessions */
if (this.sessions.length > (this.config.sessionsLimit || DEFAULT_SESSIONS_LIMIT)) {
this.sessions.flush()
Expand Down Expand Up @@ -238,11 +236,19 @@ export default class Alice {
req: WebhookRequest,
sendResponse?: (res: WebhookResponse) => void,
): Promise<any> {
const executors = [
/* proxy request to dev server, if enabled */
this.config.devServerUrl
? this.handleProxyRequest(req, this.config.devServerUrl)
: this.handleRequestBody(req, sendResponse),
await this.timeoutCallback(new Ctx({ req, sendResponse })),
].filter(Boolean)
return await Promise.race(executors)
return await this.handleRequestBody(req, sendResponse)
}

/*
* Метод создаёт сервер, который слушает указанный порт.
* Когда на указанный URL приходит POST запрос, управление
* передаётся в @handleRequestBody
*
Expand All @@ -269,11 +275,7 @@ export default class Alice {
responseAlreadySent = true
}
try {
const executors = [
this.handleRequestBody(req.body, handleResponseCallback),
await this.timeoutCallback(new Ctx({ req: req.body, sendResponse: handleResponseCallback })),
].filter(Boolean)
return await Promise.race(executors)
return await this.handleRequest(req.body, handleResponseCallback)
} catch (error) {
throw new Error(error)
}
Expand Down Expand Up @@ -320,4 +322,8 @@ export default class Alice {
protected _handleLeaveScene() {
this.currentScene = null
}

private async handleProxyRequest(request: WebhookRequest, devServerUrl: string) {
return
}
}
1 change: 1 addition & 0 deletions src/types/alice.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export interface configInterface {
sessionsLimit?: number
oAuthToken?: string
skillId?: string
devServerUrl?: string
}

0 comments on commit cece2bd

Please sign in to comment.