refactor api url

This commit is contained in:
j3d1 2019-12-17 14:32:45 +01:00
parent 9ff2739d3b
commit 489c6253c0
2 changed files with 12 additions and 8 deletions

View file

@ -2,3 +2,6 @@ root = true
[*.js] [*.js]
indent_size = 2 indent_size = 2
[*.vue]
indent_size = 2

View file

@ -15,6 +15,7 @@ const store = new Vuex.Store({
layout: 'cards', layout: 'cards',
loadedItems: [], loadedItems: [],
loadedBoxes: [], loadedBoxes: [],
apiUrl: 'https://c3lf.de/api',
}, },
getters: { getters: {
getEventSlug: state => state.route && state.route.params.event? state.route.params.event : state.events.length ? state.events[0].slug : '36C3', getEventSlug: state => state.route && state.route.params.event? state.route.params.event : state.events.length ? state.events[0].slug : '36C3',
@ -39,8 +40,8 @@ const store = new Vuex.Store({
}, },
}, },
actions: { actions: {
async loadEvents({ commit }) { async loadEvents({ commit, state }) {
const resp = await axios.get('https://c3lf.de/api/1/events', { const resp = await axios.get(`${state.apiUrl}/1/events`, {
auth: getAuth(), auth: getAuth(),
}); });
@ -53,22 +54,22 @@ const store = new Vuex.Store({
changeView({ getters }, link) { changeView({ getters }, link) {
router.push({path: `/${getters.getEventSlug}/${link.path}`}); router.push({path: `/${getters.getEventSlug}/${link.path}`});
}, },
async loadEventItems({ commit, getters }) { async loadEventItems({ commit, state, getters }) {
const resp = await axios.get(`https://c3lf.de/api/1/${getters.getEventSlug}/items`, { const resp = await axios.get(`${state.apiUrl}/1/${getters.getEventSlug}/items`, {
auth: getAuth(), auth: getAuth(),
}); });
commit('replaceLoadedItems', resp.data); commit('replaceLoadedItems', resp.data);
}, },
async loadBoxes({ commit }) { async loadBoxes({ commit, state }) {
const resp = await axios.get('https://c3lf.de/api/1/boxes', { const resp = await axios.get(`${state.apiUrl}/1/boxes`, {
auth: getAuth(), auth: getAuth(),
}); });
commit('replaceBoxes', resp.data); commit('replaceBoxes', resp.data);
}, },
async updateItem({ getters }, item) { async updateItem({ getters, state }, item) {
axios.put(`https://c3lf.de/api/1/${getters.getEventSlug}/item/${item.iid}`, item, { axios.put(`${state.apiUrl}/1/${getters.getEventSlug}/item/${item.iid}`, item, {
auth: getAuth(), auth: getAuth(),
}); });
} }