Skip to content

Commit d56bfa5

Browse files
Fabiousdunglas
authored andcommitted
fix fetch with api url suffix in vuejs (#98)
* fix fetch with api url suffix in vuejs * remove slashes * fix the problem on React also * add slash at the end of entrypoint * fix travis * better adding trailling slash
1 parent 0af39ed commit d56bfa5

File tree

6 files changed

+228
-271
lines changed

6 files changed

+228
-271
lines changed

src/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ const entrypoint =
4848
const outputDirectory =
4949
program.args[1] || process.env.API_PLATFORM_CLIENT_GENERATOR_OUTPUT;
5050

51+
const entrypointWithSlash = entrypoint.endsWith("/")
52+
? entrypoint
53+
: entrypoint + "/";
54+
5155
const generator = generators(program.generator)({
5256
hydraPrefix: program.hydraPrefix,
5357
templateDirectory: program.templateDirectory
@@ -56,16 +60,16 @@ const resourceToGenerate = program.resource
5660
? program.resource.toLowerCase()
5761
: null;
5862

59-
const parser = entrypoint => {
63+
const parser = entrypointWithSlash => {
6064
const parseDocumentation =
6165
"swagger" === program.format
6266
? parseSwaggerDocumentation
6367
: parseHydraDocumentation;
6468

65-
return parseDocumentation(entrypoint);
69+
return parseDocumentation(entrypointWithSlash);
6670
};
6771

68-
parser(entrypoint)
72+
parser(entrypointWithSlash)
6973
.then(ret => {
7074
ret.api.resources
7175
.filter(({ deprecated }) => !deprecated)

templates/react-common/actions/foo/create.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function create(values) {
1717
return dispatch => {
1818
dispatch(loading(true));
1919

20-
return fetch('/{{{name}}}', { method: 'POST', body: JSON.stringify(values) })
20+
return fetch('{{{name}}}', { method: 'POST', body: JSON.stringify(values) })
2121
.then(response => {
2222
dispatch(loading(false));
2323

templates/react-common/actions/foo/list.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function success(retrieved) {
1818
return { type: '{{{uc}}}_LIST_SUCCESS', retrieved };
1919
}
2020

21-
export function list(page = '/{{{name}}}') {
21+
export function list(page = '{{{name}}}') {
2222
return dispatch => {
2323
dispatch(loading(true));
2424
dispatch(error(''));

templates/vue/store/modules/foo/create/actions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const create = ({ commit }, values) => {
66
commit(types.{{{uc}}}_CREATE_SET_ERROR, '')
77
commit(types.{{{uc}}}_CREATE_TOGGLE_LOADING)
88

9-
return fetch('/{{{name}}}', { method: 'POST', body: JSON.stringify(values) })
9+
return fetch('{{{name}}}', { method: 'POST', body: JSON.stringify(values) })
1010
.then((response) => {
1111
commit(types.{{{uc}}}_CREATE_TOGGLE_LOADING)
1212

templates/vue/store/modules/foo/list/actions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fetch from '../../../../utils/fetch'
22
import * as types from './mutation_types'
33

4-
const getItems = ({ commit }, page = '/{{{name}}}') => {
4+
const getItems = ({ commit }, page = '{{{name}}}') => {
55
commit(types.TOGGLE_LOADING)
66

77
fetch(page)

0 commit comments

Comments
 (0)