1

I'm trying to run e2e tests on my Angular 4 app which hits my ExpressJS backend API. Running ng serve my app is served up by default on port 4200. And then separately running nodemon server.js starts my ExpressJS server on port 3000. I can use. With app.use(cors({ origin: 'http://localhost:4200', credentials: true })); I can hit my API from my Angular app just fine. However, when I try to run ng e2e the app is no longer running on port 4200 but instead 49155. So not only will my API block cross origin requests, but the tests hit the endpoing http://localhost:49155/api/endpoint instead of being proxy'd over to http://localhost/3000/api/endpoint.

I know I can run an ng serve --proxy-config proxy.conf.json which looks like

{
    "/api": {
        "target": "http://localhost:3000",
        "secure": false
    }
}

But is there any way I can do this with my ng e2e tests? And is there a way I can allow multiple cors with cors()?

gh0st
  • 1,653
  • 3
  • 27
  • 59

0 Answers0