# Serverless Deployment

Serverless deployment means that we don't need to take care of setting up or maintaining server infrastructure. Instead, we only take care of our code and the deployment is being automatically done for us.

Below you will find several serverless deployment services and explanation how to use them.

# Vercel (formerly known as Zeit)

This serverless provider allows you to deploy your code to a subdomain of their now.sh domain system.

The subdomain is generated by the value of the name property listed in the now.json file (more about this below) and a random hash string generated by the Vercel deployment service.

  1. Login in Vercel using the company account. See how to do this here (opens new window)
  2. Go to your /dashboard and click the "Import project" button.
  3. Click on the "Continue" button under "From Git Repository"
  4. Select the Git provider your repository is located at (Github, Gitlab or Bitbucket).
  5. Link your account in the selected Git provider with Vercel. This step is done only once.
  6. Select the repository that you want to deploy and click "Import"
  7. Type the project name (or use the project name as it is in the Git provider). Click "Continue".
  8. Select the root folder. It usually is the ./ directory, so leave the field empty and click "Continue".
  9. In the next screen:
  • select the used framework. This will ususally be set to "Other" because we use a custom template for most of our repositories.
  • type the build command as seen in the package.json file. For example npm run build or yarn build
  • type the output directory. For example dist or public.
  • type the development command (optional). This is usually left blank.
  • click the "Deploy" button
  1. Go in the repository and create a new file called now.json. This file should contain the following:
    {
    	"version": 2
    }
    
  2. Wait for Vercel to do its job. In a couple of minutes you should see the project deployed in your Vercel dashboard and a comment should be added by Vercel under the commit in the Git provider repository page. You will probably receive an email notification for this (and all further deployments)
  3. If you deploy a React, Angular or Vue app (a single page app), you might experience issues with the router not resolving subpages. In this case use the following in the now.json file
    {
    	"version": 2,
    	"routes": [
    		{ "handle": "filesystem" },
    		{ "src": "/.*", "dest": "/index.html" }
    	]
    }