Skip to content

Commit 97f7c9e

Browse files
committed
Export saveProjectToServer & add support for extra HTTP headers
I want to be able to send an X-CSRF-Token HTTP header when sending a POST or PUT request to create or update the project. * Exporting saveProjectToServer means that I can set the onUpdateProjectData property to a function which wraps saveProjectToServer. * Adding the optional headers parameter to the saveProjectToServer function means that the wrapping function can pass in extra HTTP headers to be sent in any request.
1 parent ff77f18 commit 97f7c9e

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {ScratchPaintReducer} from 'scratch-paint';
66
import {setFullScreen, setPlayer} from './reducers/mode';
77
import {remixProject} from './reducers/project-state';
88
import {setAppElement} from 'react-modal';
9+
import saveProjectToServer from './lib/save-project-to-server';
910

1011
const guiReducers = {
1112
locales: LocalesReducer,
@@ -27,5 +28,6 @@ export {
2728
localesInitialState,
2829
remixProject,
2930
setFullScreen,
30-
setPlayer
31+
setPlayer,
32+
saveProjectToServer
3133
};

src/lib/save-project-to-server.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ import storage from '../lib/storage';
1212
* @property {?boolean} params.isCopy a flag indicating if this save is creating a copy.
1313
* @property {?boolean} params.isRemix a flag indicating if this save is creating a remix.
1414
* @property {?string} params.title the title of the project.
15+
* @param {object} headers extra HTTP request headers.
1516
* @return {Promise} A promise that resolves when the network request resolves.
1617
*/
17-
export default function (projectId, vmState, params) {
18+
export default function (projectId, vmState, params, headers) {
1819
const opts = {
1920
body: vmState,
2021
// If we set json:true then the body is double-stringified, so don't
21-
headers: {
22-
'Content-Type': 'application/json'
23-
},
22+
headers: Object.assign({'Content-Type': 'application/json'}, headers),
2423
withCredentials: true
2524
};
2625
const creatingProject = projectId === null || typeof projectId === 'undefined';

0 commit comments

Comments
 (0)