Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setup cors for redirects under iap #688

Merged
merged 11 commits into from
Jul 20, 2018
4 changes: 2 additions & 2 deletions dashboard/backend/handler/api_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ func CreateHTTPAPIHandler(client client.ClientManager) (http.Handler, error) {
wsContainer.EnableContentEncoding(true)

cors := restful.CrossOriginResourceSharing{
ExposeHeaders: []string{"X-My-Header"},
ExposeHeaders: []string{"x-goog-authenticated-user-email"},
AllowedHeaders: []string{"Content-Type", "Accept"},
AllowedMethods: []string{"GET", "POST", "DELETE"},
CookiesAllowed: false,
CookiesAllowed: true,
Container: wsContainer,
}
wsContainer.Filter(cors.Filter)
Expand Down
46 changes: 42 additions & 4 deletions dashboard/frontend/src/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@ import { getHost } from "./utils";
const host = getHost();

export function getTFJobListService(namespace) {
return fetch(`${host}/api/tfjob/${namespace}`).then(r => r.json());
return fetch(`${host}/api/tfjob/${namespace}`, {
method: "GET",
mode: "cors",
headers: {
"Content-Type": "application/json"
},
credentials: "include",
redirect: "follow"
}).then(r => r.json());
}

export function createTFJobService(spec) {
let myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.set("mode", "cors");
myHeaders.set("credentials", "include");
myHeaders.set("redirect", "follow");
const options = {
method: "POST",
headers: myHeaders,
Expand All @@ -19,12 +30,23 @@ export function createTFJobService(spec) {
}

export function getTFJobService(namespace, name) {
return fetch(`${host}/api/tfjob/${namespace}/${name}`).then(r => r.json());
return fetch(`${host}/api/tfjob/${namespace}/${name}`, {
method: "GET",
mode: "cors",
headers: {
"Content-Type": "application/json"
},
credentials: "include",
redirect: "follow"
}).then(r => r.json());
}

export function deleteTFJob(namespace, name) {
let myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.set("mode", "cors");
myHeaders.set("credentials", "include");
myHeaders.set("redirect", "follow");
const options = {
method: "DELETE",
headers: myHeaders
Expand All @@ -36,9 +58,25 @@ export function deleteTFJob(namespace, name) {
}

export function getPodLogs(namespace, name) {
return fetch(`${host}/api/logs/${namespace}/${name}`).then(r => r.json());
return fetch(`${host}/api/logs/${namespace}/${name}`, {
method: "GET",
mode: "cors",
headers: {
"Content-Type": "application/json"
},
credentials: "include",
redirect: "follow"
}).then(r => r.json());
}

export function getNamespaces() {
return fetch(`${host}/api/namespace`).then(r => r.json());
return fetch(`${host}/api/namespace`, {
method: "GET",
mode: "cors",
headers: {
"Content-Type": "application/json"
},
credentials: "include",
redirect: "follow"
}).then(r => r.json());
}