11import { browserHistory } from 'react-router' ;
2- import axios from 'axios' ;
32import objectID from 'bson-objectid' ;
43import each from 'async/each' ;
54import isEqual from 'lodash/isEqual' ;
5+ import apiClient from '../../../utils/apiClient' ;
6+ import getConfig from '../../../utils/getConfig' ;
67import * as ActionTypes from '../../../constants' ;
78import { showToast , setToastText } from './toast' ;
89import {
@@ -14,8 +15,7 @@ import {
1415} from './ide' ;
1516import { clearState , saveState } from '../../../persistState' ;
1617
17- const __process = ( typeof global !== 'undefined' ? global : window ) . process ;
18- const ROOT_URL = __process . env . API_URL ;
18+ const ROOT_URL = getConfig ( 'API_URL' ) ;
1919
2020export function setProject ( project ) {
2121 return {
@@ -52,7 +52,7 @@ export function setNewProject(project) {
5252export function getProject ( id , username ) {
5353 return ( dispatch , getState ) => {
5454 dispatch ( justOpenedProject ( ) ) ;
55- axios . get ( `${ ROOT_URL } /${ username } /projects/${ id } ` , { withCredentials : true } )
55+ apiClient . get ( `/${ username } /projects/${ id } ` )
5656 . then ( ( response ) => {
5757 dispatch ( setProject ( response . data ) ) ;
5858 dispatch ( setUnsavedChanges ( false ) ) ;
@@ -142,7 +142,7 @@ export function saveProject(selectedFile = null, autosave = false) {
142142 fileToUpdate . content = selectedFile . content ;
143143 }
144144 if ( state . project . id ) {
145- return axios . put ( `${ ROOT_URL } /projects/${ state . project . id } ` , formParams , { withCredentials : true } )
145+ return apiClient . put ( `/projects/${ state . project . id } ` , formParams )
146146 . then ( ( response ) => {
147147 dispatch ( endSavingProject ( ) ) ;
148148 dispatch ( setUnsavedChanges ( false ) ) ;
@@ -177,7 +177,7 @@ export function saveProject(selectedFile = null, autosave = false) {
177177 } ) ;
178178 }
179179
180- return axios . post ( ` ${ ROOT_URL } /projects` , formParams , { withCredentials : true } )
180+ return apiClient . post ( ' /projects' , formParams )
181181 . then ( ( response ) => {
182182 dispatch ( endSavingProject ( ) ) ;
183183 const { hasChanges, synchedProject } = getSynchedProject ( getState ( ) , response . data ) ;
@@ -260,7 +260,7 @@ export function cloneProject(id) {
260260 if ( ! id ) {
261261 resolve ( getState ( ) ) ;
262262 } else {
263- fetch ( ` ${ ROOT_URL } /projects/${ id } `)
263+ apiClient . get ( ` /projects/${ id } `)
264264 . then ( res => res . json ( ) )
265265 . then ( data => resolve ( {
266266 files : data . files ,
@@ -287,7 +287,7 @@ export function cloneProject(id) {
287287 const formParams = {
288288 url : file . url
289289 } ;
290- axios . post ( ` ${ ROOT_URL } /S3/copy` , formParams , { withCredentials : true } )
290+ apiClient . post ( ' /S3/copy' , formParams )
291291 . then ( ( response ) => {
292292 file . url = response . data . url ;
293293 callback ( null ) ;
@@ -298,7 +298,7 @@ export function cloneProject(id) {
298298 } , ( err ) => {
299299 // if not errors in duplicating the files on S3, then duplicate it
300300 const formParams = Object . assign ( { } , { name : `${ state . project . name } copy` } , { files : newFiles } ) ;
301- axios . post ( ` ${ ROOT_URL } /projects` , formParams , { withCredentials : true } )
301+ apiClient . post ( ' /projects' , formParams )
302302 . then ( ( response ) => {
303303 browserHistory . push ( `/${ response . data . user . username } /sketches/${ response . data . id } ` ) ;
304304 dispatch ( setNewProject ( response . data ) ) ;
@@ -337,7 +337,7 @@ export function setProjectSavedTime(updatedAt) {
337337export function changeProjectName ( id , newName ) {
338338 return ( dispatch , getState ) => {
339339 const state = getState ( ) ;
340- axios . put ( `${ ROOT_URL } /projects/${ id } ` , { name : newName } , { withCredentials : true } )
340+ apiClient . put ( `/projects/${ id } ` , { name : newName } )
341341 . then ( ( response ) => {
342342 if ( response . status === 200 ) {
343343 dispatch ( {
@@ -364,7 +364,7 @@ export function changeProjectName(id, newName) {
364364
365365export function deleteProject ( id ) {
366366 return ( dispatch , getState ) => {
367- axios . delete ( `${ ROOT_URL } /projects/${ id } ` , { withCredentials : true } )
367+ apiClient . delete ( `/projects/${ id } ` )
368368 . then ( ( ) => {
369369 const state = getState ( ) ;
370370 if ( id === state . project . id ) {
0 commit comments