Skip to content

Instantly share code, notes, and snippets.

@jacopen
Last active May 10, 2021 01:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacopen/a392724565f4c5efa757ebcc5ff8855e to your computer and use it in GitHub Desktop.
Save jacopen/a392724565f4c5efa757ebcc5ff8855e to your computer and use it in GitHub Desktop.
CORS tester
apiVersion: projectcontour.io/v1
kind: HTTPProxy
metadata:
name: data
spec:
virtualhost:
fqdn: data.YOUR-DOMAIN
corsPolicy:
allowCredentials: true
allowOrigin:
- "http://cors.YOUR-DOMAIN"
allowMethods:
- GET
- POST
- OPTIONS
allowHeaders:
- authorization
- cache-control
exposeHeaders:
- Content-Length
- Content-Range
maxAge: "10m"
routes:
- conditions:
- prefix: /
services:
- name: nginx
port: 80
---
apiVersion: projectcontour.io/v1
kind: HTTPProxy
metadata:
name: cors
spec:
virtualhost:
fqdn: cors.YOUR-DOMAIN
routes:
- conditions:
- prefix: /
services:
- name: nginx
port: 80
apiVersion: v1
kind: ConfigMap
metadata:
name: html
namespace: default
data:
index.html: |
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function fetchJson() {
fetch(document.querySelector("#url").value)
.then(response => response.json())
.then(data => document.querySelector("#result").value = data.response)
.catch(error => {document.querySelector("#result").value = error})
}
</script>
</head>
<body>
<h1>CORS Test</h1>
<form>
<input type="text" id="url" value="http://data.YOUR-DOMAIN/data.json" size="40" /><br />
<input type="button" onclick="fetchJson(); return false;" value="Fetch" /><br />
<input type="textbox" id="result" size="40" />
</form>
</body>
</html>
data.json: |
{"response": "Success"}
---
apiVersion: v1
kind: Pod
metadata:
name: nginx
namespace: default
labels:
run: nginx
spec:
containers:
- image: nginx
name: nginx
volumeMounts:
- mountPath: /usr/share/nginx/html
name: html
volumes:
- name: html
configMap:
name: html
---
apiVersion: v1
kind: Service
metadata:
labels:
run: nginx
name: nginx
namespace: default
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
run: nginx
type: ClusterIP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment