Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

291
Vistas
Is this javascript frontend, NodeJS backend scenario viable to work?

I have a Domain-A which is static site built on netlify to provide shopping cart facilities.

I have a Domain-B server backend running a payment on Node.JS, and processing Auth Services via passport.js.

As a static site on Netlify this Domain-A cannot provide any backend services. The user sees this domain's web pages, selects products, and eventually presses a buy button. This button invokes JS code running in the browser, sending an AJAX /login to Domain-B. It successfully logs in. It returns a connect.sid cookie to Domain-A with SameSite:none, Secure:true. I can see the cookie with Chrome Debugger.

After a successful login return from Domain-B, Domain-A now sends an AJAX GET to Domain-B requesting seller and payment information. But the GET always fails with a 403 "User Not Logged In".

The AJAX GET includes

crossDomain: true,
headers: { 
    "Content-Type": "text/plain",
    "withCredentials": true
},

The Content-Type is to make it a CORS Simple Get and avoid Preflight issues, the withCredentials to make sure the cookie is included with the GET. I tried using a POST but it seems to always trigger Preflight processing which creates a lot of other complexities.

My basic question is, should I be able to do this, login and perform a GET from browser code of the Domain-A static site, to a NodeJS server on Domain-B? OR, must I get off Netlify and put it onto something like DigitalOcean where Domain-A has a backend which can login and get or post to Domain-B?

Is there sample code somewhere where I can copy the structure to my scenario?

UPDATE: 2022-02-20 This is my server side cors() code:

var corsOptions = {
  "origin": 'https://www.chicagomegashop.com',
  "methods": "GET, PUT, POST, DELETE, HEAD, OPTIONS",
  "credentials": true,
  "allowedHeaders": ['Content-Type'],
  "optionsSuccessStatus": 204
};

app.use(cors(corsOptions));

Regarding my concern that no cookie is being saved. Here is the cookie as it arrives as a Response Header: enter image description here

enter image description here

But now, when checking for the cookie at the domain, it is not there:

enter image description here

IS something wrong or am I not interpreting what I see correctly?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

try moving withCredentials outside of headers

crossDomain: true,
headers: { 
    "Content-Type": "text/plain",
},
withCredentials: true

Also, on your backend server, do you have cors configured to allow what your frontend is trying to do?

 cors({
    origin: 'netlifysite_uri',
    credentials: true,
    allowedHeaders: ['Content-Type'],
  })
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda