Skip to content

Commit

Permalink
Add CORS proxy tool (#575)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcamise-gpsw committed Jul 24, 2024
1 parent 1da7f15 commit 9075a90
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tools/cors_proxy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM nginx:alpine

WORKDIR /etc/nginx
COPY ./nginx.conf ./conf.d/default.conf
ENTRYPOINT [ "nginx" ]
CMD [ "-g", "daemon off;" ]
27 changes: 27 additions & 0 deletions tools/cors_proxy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# CORS NGINX Docker Proxy

## What is this?

This is a simple [NGINX](https://www.nginx.com/) docker server to
append [CORS headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) to HTTP responses from a GoPro camera.
This proxy accepts input on port 80 and forwards it to `http:10.5.5.9:8080`

## How do I use it?

It is intended to be run using the `docker-compose.yml` here via:

```
docker compose up
```

Once running, an HTTP-connected-GoPro can be communicated with by replacing the default `10.5.5.9:8080` with
`localhost:8082`. For example you can get the state via:

```
curl http://localhost:8082/gopro/camera/state
```

## Future work

- [ ] Allow the camera IP and port to be set at run-time
- [ ] Add camera HTTPS support
7 changes: 7 additions & 0 deletions tools/cors_proxy/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
cors_proxy:
container_name: cors_proxy
build:
context: .
image: tcamise/gopro-cors-proxy
ports: ['8082:80']
32 changes: 32 additions & 0 deletions tools/cors_proxy/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
upstream api {
server 10.5.5.9:8080;
}

server {
listen 80;
server_name localhost;

add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,
X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range' always;
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH' always;

location / {

if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Max-Age' 1728000 always;
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,
X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range' always;
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH' always;
return 204;
}

add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,
X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range' always;
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH' always;

proxy_pass http://10.5.5.9:8080/;
}
}

0 comments on commit 9075a90

Please sign in to comment.