File tree Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -229,9 +229,9 @@ export default class Route implements IMountableItem {
229229
230230 asExpressRoute ( ) {
231231 return async ( req : express . Request , res : express . Response ) => {
232- const { query, params } = req ;
232+ const { query, params, body } = req ;
233233
234- const providedVariables = { ...query , ...params } ;
234+ const providedVariables = { ...query , ...params , ... body } ;
235235
236236 // Assemble variables from query, path and default values
237237 const assembledVariables = this . assembleVariables ( providedVariables ) ;
@@ -247,11 +247,12 @@ export default class Route implements IMountableItem {
247247 return ;
248248 }
249249
250- const { statusCode, body } = await this . makeRequest ( assembledVariables , headers ) ;
250+ const { statusCode, body : responseBody } =
251+ await this . makeRequest ( assembledVariables , headers ) ;
251252
252253 res
253254 . status ( statusCode )
254- . json ( body ) ;
255+ . json ( responseBody ) ;
255256 } ;
256257 }
257258
Original file line number Diff line number Diff line change 66} from '.' ;
77import Route from './Route' ;
88import express from 'express' ;
9+ import bodyParser from 'body-parser' ;
910import axios , { AxiosInstance , AxiosRequestConfig } from 'axios' ;
1011import { parse , DocumentNode , getOperationAST } from 'graphql' ;
1112import { version } from './package.json' ;
@@ -124,13 +125,20 @@ export default class Router {
124125 return mountedItem ;
125126 }
126127
128+ // TODO: Temporarily using express as metal
127129 listen ( port : number , callback ?: ( ) => void ) {
128- throw new Error ( 'Not Implemented' ) ;
130+ const router = express ( ) ;
131+
132+ router . use ( this . asExpressRouter ( ) ) ;
133+
134+ router . listen ( port , callback ) ;
129135 }
130136
131137 asExpressRouter ( ) {
132138 const router : any = express . Router ( ) ;
133139
140+ router . use ( bodyParser . json ( ) ) ;
141+
134142 [ ...this . modules , ...this . routes ] . forEach ( ( route ) => {
135143 const { path, httpMethod } = route ;
136144 const routeFn = route . asExpressRoute ( ) ;
You can’t perform that action at this time.
0 commit comments