Skip to content

Commit

Permalink
feat: add zeabur preset (#1942)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuaanlin authored Nov 30, 2023
1 parent 36e0739 commit 081aa27
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Temporary Items
staticwebapp.config.json
.eslintcache
playground/firebase.json
.zeabur

test/fixture/functions

Expand Down
2 changes: 1 addition & 1 deletion docs/content/2.deploy/0.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ When deploying to the production using CI/CD, Nitro tries to automatically detec
- [netlify](/deploy/providers/netlify)
- [stormkit](/deploy/providers/stormkit)
- [vercel](/deploy/providers/vercel)

- [zeabur](/deploy/providers/zeabur)

## Changing the deployment preset

Expand Down
22 changes: 22 additions & 0 deletions docs/content/2.deploy/20.providers/zeabur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Zeabur

Deploy Nitro apps to [Zeabur](https://zeabur.com).

**Preset:** `zeabur` ([switch to this preset](/deploy/#changing-the-deployment-preset))

::alert
**Zero Config Provider**
:br
Integration with this provider is possible with zero configuration. ([Learn More](/deploy/#zero-config-providers))
::

::alert{type="warning"}
This preset is experimental and available to try via [nightly channel](/guide/getting-started#nightly-release-channel).
::

## Deploy using Git

1. Push your code to your git repository (Currently only GitHub supported).
2. [Import your project](https://zeabur.com/docs/get-started) into Zeabur.
3. Zeabur will detect that you are using Nitro and will enable the correct settings for your deployment.
4. Your application is deployed!
1 change: 1 addition & 0 deletions src/presets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ export { iis, iisHandler, iisNode } from "./iis";
export { _static as static } from "./static";
export * from "./github-pages";
export * from "./winterjs";
export * from "./zeabur";
49 changes: 49 additions & 0 deletions src/presets/zeabur.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import fsp from "node:fs/promises";
import { dirname, relative, resolve } from "pathe";
import { writeFile } from "../utils";
import { defineNitroPreset } from "../preset";
import type { Nitro } from "../types";

// https://zeabur.com/docs/advanced/serverless-output-format

export const zeabur = defineNitroPreset({
extends: "node",
entry: "#internal/nitro/entries/zeabur",
output: {
dir: "{{ rootDir }}/.zeabur/output",
serverDir: "{{ output.dir }}/functions/__nitro.func",
publicDir: "{{ output.dir }}/static",
},
commands: {
deploy: "",
preview: "",
},
hooks: {
async compiled(nitro: Nitro) {
const buildConfigPath = resolve(nitro.options.output.dir, "config.json");
const cfg = {
containerized: false,
routes: [{ src: ".*", dest: "/__nitro" }],
};
await writeFile(buildConfigPath, JSON.stringify(cfg, null, 2));

// Write ISR functions
for (const [key, value] of Object.entries(nitro.options.routeRules)) {
if (!value.isr) {
continue;
}
const funcPrefix = resolve(nitro.options.output.serverDir, ".." + key);
await fsp.mkdir(dirname(funcPrefix), { recursive: true });
await fsp.symlink(
"./" + relative(dirname(funcPrefix), nitro.options.output.serverDir),
funcPrefix + ".func",
"junction"
);
await writeFile(
funcPrefix + ".prerender-config.json",
JSON.stringify({ type: "Prerender" })
);
}
},
},
});
9 changes: 9 additions & 0 deletions src/runtime/entries/zeabur.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import "#internal/nitro/virtual/polyfill";
import { NodeListener, toNodeListener } from "h3";
import { nitroApp } from "../app";

const handler = toNodeListener(nitroApp.h3App);

export default <NodeListener>function (req, res) {
return handler(req, res);
};

0 comments on commit 081aa27

Please sign in to comment.