A boilerplate for building apllication with serverless and nextjs framework. It supports auto deployment with Gitlab-CI.
-
Install serverless framework globally:
npm install -g serverless
-
Copy and create a new .env file from .env.example in ./app and ./apis folder.
-
Install dependencies:
yarn install
-
Run in dev mode:
yarn start
We use a custom server with Express to handle custom routing of the Next app in server side. Beside, the apis are served with the help of serverless-offline plugin.
-
To deploy to staging or production add the environment variables in .env files in ./app and ./apis folder corresponding to the deployment environment and run bellow command.
yarn deploy
It will deploy the Next app and also the apis to AWS Lambda. Each page in the Next app will become one Lambda function. All static resources will be uploaded to S3.