I have a webapp that works with Nuxt as a frontend and Laravel as a backend and Axios as a bridge between the frontend and the backend. In local it works fine but when I go on production mode it doesn't work and I get this error:
GET http://localhost:8001/sanctum/csrf-cookie net::ERR_CONNECTION_REFUSED
On my .env file I have this configuration:
#Backend
SESSION_DOMAIN=157.230.109.19:8001
#Frontend
SANCTUM_STATEFUL_DOMAINS=157.230.109.19:3000
And in Nuxt I have defined a plugin file called axios.js:
import axios from "axios"
export default defineNuxtPlugin((NuxtApp) => {
// Tutte le richieste richiedono che l'utente sia loggato
axios.defaults.withCredentials = true;
axios.defaults.baseURL = 'http://localhost:8001'
// axios.defaults.baseURL = 'http://157.230.109.19:8001/'
return {
provide: {
axios: axios
}
}
})
I have to work with IP addresses because right now I don't have a domain for the application.
To replicate the error you have to go here: http://157.230.109.19/login and click the login button (the email and password fields could be empty).
On the Nuxt Plugin I have tried to change the baseUrl with the server IP address or with localhost but it doesn't work.
In Postman I have tried to call on http://localhost:8000/sanctum/csrf-cookie and I get the cookies, but when I try to call http://157.230.109.19:8001/sanctum/csrf-cookie it return 'No cookies received from the server'