Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/evanshortiss/cors-nginx-blogpost
https://github.com/evanshortiss/cors-nginx-blogpost
Last synced: 21 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/evanshortiss/cors-nginx-blogpost
- Owner: evanshortiss
- Created: 2023-07-26T21:00:46.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-08-04T23:56:35.000Z (over 1 year ago)
- Last Synced: 2024-04-09T13:09:27.270Z (7 months ago)
- Language: Dockerfile
- Size: 4.12 MB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Avoiding CORS with an NGINX Proxy
This repository contains a sample solution for avoid Cross-Origin Resource
Sharing (CORS) issues by serving your HTML, CSS, JavaScript, and API endpoints
from the same origin.
## Deploy on OpenShift
Use the following commands to deploy this application on OpenShift, e.g th free
[OpenShift Developer Sandbox](https://developers.redhat.com/developer-sandbox):```bash
# Clone and change directory into the repository
git clone https://github.com/evanshortiss/cors-nginx-blogpost
cd cors-nginx-blogpost# Get the current namespace/project name
export NAMESPACE=$(oc project -q)# Set the target repository. If you fork the repository you can use your
# fork's URL in place of this URL
export SOURCE_REPOSITORY="https://github.com/evanshortiss/cors-nginx-blogpost"# Deploy the frontend
oc process -f manifests/frontend.yaml -p NAMESPACE=$NAMESPACE -p SOURCE_REPOSITORY=$SOURCE_REPOSITORY | oc apply -f -# Deploy the backend
oc process -f manifests/backend.yaml -p NAMESPACE=$NAMESPACE -p SOURCE_REPOSITORY=$SOURCE_REPOSITORY | oc apply -f -
```To clean up all the resources associated with this solution, use this command:
```bash
oc delete all -l 'app in (react-ui,quarkus-backend)'
```## Local Development
Requirements:
* Node.js v18
* JDK v17
* Maven v3.8Start the Quarkus backend:
```bash
cd quarkus-backend
./mvnw quarkus:dev
```Then start the React frontend:
```bash
cd react-ui
npm run dev
```## Enabling CORS on the Backend
If you'd like to experiment with CORS enabled on the Quarkus backend, you can configure CORS per the [Quarkus HTTP Reference](https://quarkus.io/guides/http-reference).
For example, to allow any domain to access the Quarkus backend:
```bash
QUARKUS_HTTP_CORS=true \
QUARKUS_HTTP_CORS_ORIGINS=* \
./mvnw quarkus:dev
```Of course, the idea behind this example is to avoid the need to do this by using
NGINX as a proxy!