|
1 | 1 | # Serverless-side rendering with Vue.js and Nuxt.js
|
2 | 2 |
|
3 |
| -Sample project for using Nuxt.js to create a server-side rendered Vue.js app on AWS Lambda and AWS API Gateway. Can easily integrate with your own API or 3rd party APIs such as headless CMS, e-commerce or serverless architecture. |
| 3 | +This project demonstrates how to use Nuxt.js to create a server-side rendered Vue.js app on AWS Lambda and AWS API Gateway. |
4 | 4 |
|
5 |
| -Full [tutorial is here](https://dev.to/adnanrahic/a-crash-course-on-serverless-side-rendering-with-vuejs-nuxtjs-and-aws-lambda-1nk4). |
| 5 | +## Use-cases |
| 6 | +- Develop single-page apps without worrying about SEO optimization. |
| 7 | + |
| 8 | +## Benefits |
| 9 | +- SEO boost server-side rendering provides |
| 10 | +- Speed of a Single Page Application\ |
| 11 | +- Cheap hosting in a serverless environment on AWS Lambda |
| 12 | +- Easy deployment with the Serverless Framework |
| 13 | +- Can easily integrate with your own API or 3rd party APIs such as headless CMS, e-commerce or serverless architecture. |
| 14 | + |
| 15 | +## How it works |
| 16 | +Well, first thing's first. We want a super fast Single Page Application. But, this usually comes with a cost. Lousy SEO capabilities. That won't do, meaning we also want the app to have server-side rendering. Okay, sounds simple. We'll grab Nuxt.js, which is a framework for creating universal Vue.js applications, and configure it to server-side render our pages. |
| 17 | + |
| 18 | +To accomplish this we need to spin up a simple Express server and configure the Nuxt renderer to serve files through Express. It is way simpler than it sounds. |
| 19 | + |
| 20 | +## Setup |
| 21 | +- Install dependencies: |
| 22 | + ```bash |
| 23 | + $ npm i |
| 24 | + ``` |
| 25 | +- [Create public wildcard certificate](https://docs.aws.amazon.com/acm/latest/userguide/gs-acm-request-public.html) for your domain (AWS ACM) |
| 26 | + |
| 27 | +## Deploy |
| 28 | +1. **Deploy service without custom domain:** |
| 29 | + |
| 30 | + ```bash |
| 31 | + $ sls deploy |
| 32 | + ``` |
| 33 | + |
| 34 | + Once deployed you'll have your app running on a default API Gateway URI. |
| 35 | +
|
| 36 | +2. **Create domain:** |
| 37 | +
|
| 38 | + Uncomment domain settings in `serverless.yaml`. |
| 39 | + ```yaml |
| 40 | + [...] |
| 41 | + plugins: |
| 42 | + - serverless-apigw-binary |
| 43 | + - serverless-domain-manager # uncomment the plugin |
| 44 | + - serverless-offline |
| 45 | + [...] |
| 46 | + custom: |
| 47 | + secrets: ${file(secrets.json)} |
| 48 | + apigwBinary: |
| 49 | + types: |
| 50 | + - '*/*' |
| 51 | + customDomain: # uncomment the whole customDomain section |
| 52 | + domainName: ${self:custom.secrets.DOMAIN} |
| 53 | + basePath: '' |
| 54 | + stage: ${self:custom.secrets.NODE_ENV} |
| 55 | + createRoute53Record: true |
| 56 | + ``` |
| 57 | +
|
| 58 | + Run the create domain command: |
| 59 | + ```bash |
| 60 | + $ sls create_domain |
| 61 | + ``` |
| 62 | + This will take a few minutes, go grab a coffee in the meantime. :smile: |
| 63 | +
|
| 64 | +3. **Re-deploy the service with the domain settings:** |
| 65 | +
|
| 66 | + ```bash |
| 67 | + $ sls deploy |
| 68 | + ``` |
| 69 | +
|
| 70 | + Output: |
| 71 | + ```bash |
| 72 | +
|
| 73 | + ``` |
| 74 | +
|
| 75 | +
|
| 76 | +## Usage |
| 77 | +Navigate to `vuessr-yourdomain.com` or whichever domain you picked. You'll se the Vue.js SPA running. |
| 78 | + |
| 79 | +--- |
| 80 | + |
| 81 | +I've written a detailed tutorial about the process. You can check it out [here](https://dev.to/adnanrahic/a-crash-course-on-serverless-side-rendering-with-vuejs-nuxtjs-and-aws-lambda-1nk4). |
0 commit comments