Serverless Output Format
Zeabur supports both containerized and serverless deployment. When you deploy your project to Zeabur, Zeabur will use zbpack (opens in a new tab) to analyze and build your project automatically. You can find more information about the build process in Builds.
Containerized deployment requires more computing resources, because even if the service is not in use, it needs to be kept open to maintain various internal states of the service. The serverless deployment method decomposes the service into multiple serverless functions that can be used immediately. When the service receives an external request, it executes the function to calculate and return the result, thereby providing higher scalability and saving unnecessary costs.
Build Output Format
Without any additional configuration, zbpack will choose whether to use the serverless method based on the development framework used by the project. If zbpack decides to use the serverless method for building, you can find the .zeabur/output
directory in the project directory after the build is completed. The structure under the directory is as follows:
.zeabur/output
├── static
│ ├── index.html
│ └── ...
├── functions
│ ├── index.func
│ └── ...
The static
directory stores static resources such as HTML, CSS, JavaScript, etc., and the functions
directory stores serverless functions. Each directory ending with .func
is a function entry, and they correspond to a path after the service is deployed online, for example:
functions/index.func
corresponds to the path/
functions/users/get.func
corresponds to the path/users/get
functions/api/orders.func
corresponds to the path/api/orders
functions/api/orders/[id].func
corresponds to the path/api/orders/[id]
, where[id]
is a dynamic path that can match any path.
To maximize the compatibility of the build output, zbpack's serverless build output format is as consistent as possible with Vercel (opens in a new tab)'s Build Output API (v3) (opens in a new tab). In this way, the authors and teams of existing frameworks or new frameworks in the future do not need to re-develop adapters for different platforms.
Pure Static Output
For purely static website frameworks, such as Vite (opens in a new tab), etc., there will only be a static
directory in the .zeabur/output
directory after zbpack is built, and there is no functions
directory. This is because purely static website frameworks do not need to use the serverless method for deployment, so zbpack will directly package all static resources into the static
directory, and directly deploy the resources in the static
directory to the CDN during deployment.
Serverless Functions
For frameworks that need to use Serverless, such as Next.js (opens in a new tab) or Nuxt.js (opens in a new tab), etc., there will be two directories, static
and functions
, in the .zeabur/output
directory after zbpack is built. The static
directory stores static resources, and the functions
directory stores serverless functions.
Currently, the deployment of serverless functions is still in the beta stage. If you want to deploy services in a serverless manner, you need to add the EXPERIMENTAL_SERVERLESS=1
environment variable during the build.
If your project or a framework can be deployed using serverless functions, but zbpack has not yet supported it, please feel free to submit an Issue or Pull Request on GitHub (opens in a new tab).
For services deployed on Zeabur, you can see whether they are currently deployed using the serverless method or the containerized method in the upper right corner of the service details page:
Incremental Static Regeneration (ISR)
To maximize the advantages of Serverless deployment, Zeabur supports the "Incremental Static Generation" (ISR) function, which allows a page to be both a static resource and a serverless function. When a user opens the website, he can see the content of the page from the static resource at a very fast speed. At this time, Zeabur will re-request the serverless function in the background and update the result to the static resource for the next visit.
In this way, users can enjoy the advantages of the serverless deployment method without affecting the experience, and it is also very helpful for the SEO of the website.
To enable the ISR function for a serverless function, just add a .prerender-config.json
with the same name next to the .func
folder of the output result:
{
"expiration": "1h"
}
The expiration
is an optional attribute used to set the time interval for Zeabur to use the serverless function to re-render the page.