Skip to content
This repository was archived by the owner on Jun 23, 2020. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 9 additions & 3 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,15 +321,21 @@ export class Service {
}

static async sendJson(method: string, url: string, json: object): Promise<any> {
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;
Expand All @@ -348,7 +354,7 @@ export class Service {
static async getJson(url: string): Promise<any> {
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()}`);
Expand Down