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

Feature/add cors headers #19

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
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
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,36 @@ This configuration limits memory usage to 512mb. This should be enough for most
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"` environment variable in `docker-compose.elasticsearch.yaml`
```

## CORS settings

To better support decoupled architecture testing, HTTP.CORS configuration to expose the server to any origin is in place.

```yaml
- "http.cors.allow-origin=*"
- "http.cors.enabled=true"
- "http.cors.allow-headers=X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization,Access-Control-Allow-Origin,Access-Control-Request-Headers"
- "http.cors.allow-credentials=true"
- "http.cors.allow-methods: OPTIONS, HEAD, GET, POST, PUT, DELETE"
```

When paired with a frontend request with the proper headers, this should allow for cross-origin requests.

```script
// Example JS fetch() with headers
fetch('http://vca.ddev.site:9200/elasticsearch_index_db/_search', {
method: 'post',
body: querystring,
//headers: { 'Content-Type': 'application/json' },
headers: {
'Origin': 'http://localhost:8000',
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
'Access-Control-Request-Headers': 'access-control-allow-origin,content-type',
},
})
```


If you change this variable, make sure to remove the `#ddev-generated` line at the top of the file.

You can use `ddev logs -s elasticsearch` to investigate what the elasticsearch daemon has been up to, or if you have a RAM-related crash.
Expand Down
5 changes: 5 additions & 0 deletions docker-compose.elasticsearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ services:
- VIRTUAL_HOST=$DDEV_HOSTNAME
- HTTP_EXPOSE=9200:9200
- HTTPS_EXPOSE=9201:9200
- "http.cors.allow-origin=*"
- "http.cors.enabled=true"
- "http.cors.allow-headers=X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization,Access-Control-Allow-Origin,Access-Control-Request-Headers"
- "http.cors.allow-credentials=true"
- "http.cors.allow-methods: OPTIONS, HEAD, GET, POST, PUT, DELETE"
Comment on lines +18 to +22
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these environment variables? Or some other type of configuration? Dots in environment variables are unusual. And who consumes this information?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

labels:
com.ddev.site-name: ${DDEV_SITENAME}
com.ddev.approot: $DDEV_APPROOT
Expand Down
Loading