#how to configure production url

22 messages · Page 1 of 1 (latest)

glass nest
#

I am looking to deploy my angular project. I currently tell it which api url to hit through a proxy.config.json { "/api/*": { "target": "http://localhost:3000", "secure": false }, "/__/*": { "target": "http://localhost:3100", "secure": false } }and i start up my app with ng serve --proxy-config proxy.config.json what do i need to do to make it point to my deployed API for when i deploy my application. i.e locally i want it to hit localhost but deployed i want it to hit my production api url.

lone shale
#

Generally you do that using environment.ts and enviornment.prod.ts

glass nest
#

what do i need to do for example, environment.ts to tell it to hit localhost:3000?

glass nest
#

i see, and when starting the app how will it know what environment im in?

#

just got it to work

#

though im running into this Access to XMLHttpRequest at 'http://localhost:3000/api/auth/login' from origin 'http://localhost:4200' has been blocked by CORS policy: which i wasnt before

lone shale
#

--configuration flag. The default for ng build is "production" as defined in angular.json

#

Sounds like you have your configurations backwards

glass nest
#

localhost 4200 is the frontend, and 3000 is the backend

lone shale
#

What did you do?

glass nest
#

i was using proxy.config.json before so i wasnt running into issues

#

i just spun it up with ng serve

#

and i am seeing this cors issue

lone shale
#

You still need the proxy with localhost. Or better fix your API server to do CORS

glass nest
#

im trying to the latter actually now

#

what are cors and why are they asking me for it?

#

is it to check the integrity of the request i.e where its coming from?

lone shale
#

You understand that ng serve is not for production, right?

glass nest
#

yes

lone shale
#

g!cors @glass nest

mossy muralBOT