diff --git a/package.json b/package.json index 49c96e7..f07f3aa 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "build": "webpack --mode production && yarn templates", "build-prod": "yarn build && node bin/update-config.js && mkdir -p build/ && cp -R config.json index.html favicon.ico lib style dist img fonts misc build/ && ./debug-build.sh", "build-watch": "webpack --watch --mode development", - "dev-server": "yarn templates && webpack-dev-server -d --http --port 28443", + "dev-server": "yarn templates && webpack-dev-server -d --https --port 28443", "start": "yarn dev-server", "test": "yarn jest && yarn tslint && yarn test:bundle", "test:ci": "yarn coverage && yarn coveralls", diff --git a/src/service.ts b/src/service.ts index c6ef7ac..b5d82e6 100644 --- a/src/service.ts +++ b/src/service.ts @@ -321,15 +321,21 @@ export class Service { } static async sendJson(method: string, url: string, json: object): Promise { + const savedCookiesJson = window.localStorage.getItem('fiddle-cookies'); + const cookies = savedCookiesJson ? JSON.parse(savedCookiesJson) : {}; + const headers = new Headers({ "Content-Type": "application/json; charset=utf-8", ...cookies }); const response = await fetch(url, { - credentials: "include", method: method, body: JSON.stringify(json), - headers: new Headers({ "Content-type": "application/json; charset=utf-8" }) + headers }); if (!response.ok) { throw new Error(`${response.status}: ${await response.text()}`); } + const setCookies = response.headers.get('Set-Cookie'); + if (setCookies) { + window.localStorage.setItem('fiddle-cookies', JSON.stringify(setCookies)); + } if (response.status === 204) { // No Content return null; @@ -348,7 +354,7 @@ export class Service { static async getJson(url: string): Promise { const response = await fetch(url, { credentials: "include", - headers: new Headers({ "Content-type": "application/json; charset=utf-8" }) + headers: new Headers({ "Content-Type": "application/json; charset=utf-8" }) }); if (!response.ok) { throw new Error(`${response.status}: ${await response.text()}`);