I'm having some issues on EC2 instance, where I'm trying to deploy app.
BE:
app = FastAPI(title="App", openapi_url="/openapi.json")
origins = ['http://localhost']
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"]
)
FE:
axios.get('http://localhost:8000/search/?' + searchQuery)
.then((res) => {
setData(JSON.parse(res.data));
});
I'm using also Ngnix with following config:
server {
listen 80;
location / {
root /usr/share/nginx/html/;
include /etc/nginx/mime.types;
try_files $uri $uri/ /index.html;
}
}
So if launch the prod version locally, everything works fine, but on EC2 I'm getting CORS error while trying to fetch data with axios:
- Chrome: Cross-Origin Resource Sharing error: InsecurePrivateNetwork
- Firefox: CORS Missing Allow Origin
Not sure, what am I missing, should I configure nginx proxy so that public IP of EC2 will be sending requests as localhost? (I was trying also to set origins=[*] but that didn't help)