Skip to content

Commit

Permalink
Fix route guesser
Browse files Browse the repository at this point in the history
  • Loading branch information
asvae committed Aug 22, 2016
1 parent a88f388 commit 9a4c9e8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
14 changes: 1 addition & 13 deletions resources/assets/js/components/edit-block/edit-block.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import vmRequestEditor from './request-editor/request-editor.vue'
import vmResponseViewer from './response-viewer/response-viewer.vue'
import RandExp from 'randexp'
import {scheduleRequest, setRequestInfo, setResponse} from '../../vuex/actions.js'
import requestEditorData from './request-editor/request-editor-data.js'
Expand Down Expand Up @@ -50,16 +48,6 @@
// process the request as usual and won't give any info.
request.headers.push({key: 'X-Api-Tester', value: 'route-info'})
// Modifies path if wheres are declared in request.
// Otherwise, we'll send to unmodified path.
let wheres = _.cloneDeep(request.wheres)
for (let index in wheres) {
let mocker = new RandExp(new RegExp(wheres[index]))
let dummy = new RegExp('{' + index + '}', 'g')
request.path = request.url.replace(dummy, mocker.gen())
}
// Do sending.
this.$api.ajax(request.method, request.url, request.data, request.headers).then((response) => {
this.setRequestInfo(response.data)
Expand Down
16 changes: 15 additions & 1 deletion resources/assets/js/components/routes/route.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,30 @@
} from '../../vuex/actions.js'
import vmMethodButton from '../ligth-components/method-button.vue'
import _ from 'lodash'
import RandExp from 'randexp'
export default {
components: {
vmMethodButton
},
computed: {
routeRequest (){
// Modifies path if wheres are declared in request.
// Otherwise, we'll send to unmodified path.
let path = this.route.path
let wheres = this.route.wheres
for (let index in wheres) {
let mocker = new RandExp(new RegExp(wheres[index]))
let dummy = new RegExp('{' + index + '}', 'g')
path = path.replace(dummy, mocker.gen())
}
console.log(path)
return {
method: this.route.methods[0],
path: this.route.path,
path: path,
name: "",
body: this.route.hasOwnProperty('body') ? this.route.body : "",
wheres: this.route.hasOwnProperty('wheres') ? this.route.wheres : {},
Expand Down

0 comments on commit 9a4c9e8

Please sign in to comment.