Stuff I'm Up To

Technical Ramblings

Laravel, Nuxt.js and Nginx — October 2, 2019

Laravel, Nuxt.js and Nginx

Whilst experimenting with Nuxt.js (A Vue.js framework) as a front end client for Laravel I discovered I was going to face some issues with CORS, certificates for HTTPS and the whole serving the client over port 3000 and the API over port 80 thing.

In the development environment this isn’t so bad as I can run both the Laravel artisan web server and serve Nuxt.js and have them talk to each other – within reason. The problems started when I wanted to use Social Sign In using Facebook, Google etc. The callback from the OAuth process would fire, but the client would fail with CORS errors as I would have to redirect the client using the API from the OAuth callback.

To resolve this issue I tried adding in a CORS module for Laravel and setting the values appropriately, but still failed.

So I began thinking what this would look like in production. I wouldn’t want to serve the API and client separately and I’d probably put them both behind a reverse proxy, so let’s look at using Nginx.

Continue reading