-1

I have an Angular app running in gh-pages https://yourweatherapp.github.io/yourweatherapp.github.io which make requests to a node.js app that it´s running in a host.

Previously, I have consulted other info on the net like this How to allow CORS?, but solutions don´t work for me

I have configured the node.js app to allow request from this origin on this way:

const corsMiddleware = cors({
    origin: [process.env.URL, 'https://yourweatherapp.github.io/yourweatherapp.github.io/login']
  })

  app.use(corsMiddleware)
  app.options('*', corsMiddleware) 

But the browser doesn´t allow to receive the answer and do login.

What am I doing wrong?

Carlos FTG
  • 81
  • 1
  • 12

1 Answers1

0
'https://yourweatherapp.github.io/yourweatherapp.github.io/login'

Look at the error message in the browser console. It will tell you the origin that doesn't have permission to read the data, and it won't be that.

Origins do not include paths. So that is not a valid origin.

It should be only https://yourweatherapp.github.io

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • I have tried 'https://yourweatherapp.github.io', but it doesn´t work. Could it be gh-pages problem or a problem from the host? – Carlos FTG Nov 26 '18 at 22:12
  • You also need to have a server hosting the URL you are requesting. https://wheatherapp.com:8080/api/login is just not connecting. – Quentin Nov 26 '18 at 22:13
  • The url is running in a2hosting, it works if I do requests from postman – Carlos FTG Nov 26 '18 at 22:21
  • I think I have detected the problem, but I it´s still failling. If I run the front-end from local, I can get the back-end methods on the server, but if I try from www.wheatherapp.com (sorry for wheather, I have to change that to weather). I have a CORS problem even when I have changed the CORS permisses to const corsMiddleware = cors({ origin: [process.env.URL, 'http://wheatherapp.com:8080'] //origin: [process.env.URL, 'http://localhost:4200'] }) app.use(corsMiddleware) app.options('*', corsMiddleware) – Carlos FTG Dec 11 '18 at 19:36