Yes, I use http://localhost and ports is 3001 for API and 3000 frontend, but i use nginx for bring everyone together on port 80, this is configuration the nginx:
server {
listen 80;
location / {
proxy_pass http://host.docker.internal:3001; # Svelte app
proxy_http_version 1.1;
proxy_set_header Host host.docker.internal:3001; # Define o cabeçalho Host necessário para o sveltekit
proxy_set_header Origin http://host.docker.internal:3001; # Define o cabeçalho Origin necessário para o sveltekit
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_cache_bypass $http_upgrade;
client_max_body_size 2M;
}
location /api/ {
proxy_pass http://host.docker.internal:3000; # Rust API
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
client_max_body_size 2M;
}
}
I testing cookie trying access private endpoint in my API and seeing console browser:
Hmm. I notice that your postman screenshot shows a request to http://localhost:3000/api/login while your devtools screenshot shows a request to http://localhost:8080/login. Does postman have the same behavior if you change it to use the same URL? Are any other request headers different?
The request to http://localhost:8080/login is in frontend with sveltekit and the backend of sveltekit do request for API, how next code (code with typescript):
export const actions = {
default: async (event: RequestEvent) => {
const { request, locals, cookies } = event
const tutorIAAPI = locals.tutorIAAPI as TutorIAAPI
const form = await superValidate(request, zod(authSchema))
if (!form.valid) {
return fail(400, { form })
}
const responseData = await tutorIAAPI.fetchWrapper(
'login',
{
method: 'POST',
body: form.data
}
)
if (responseData.error) {
setFlash({ type: 'error', message: 'Não foi possível realizar o login.'}, cookies)
return fail(400, { form })
}
redirect("/dashboard", { type: 'success', message: 'Login realizado com sucesso!'}, cookies)
}
}
the fetch request to http://localhost:8080/api/login