create-nifra 0.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +33 -0
- package/dist/agents.d.ts +22 -0
- package/dist/agents.d.ts.map +1 -0
- package/dist/agents.js +259 -0
- package/dist/agents.js.map +1 -0
- package/dist/auth.d.ts +30 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +90 -0
- package/dist/auth.js.map +1 -0
- package/dist/cli.d.ts +101 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +450 -0
- package/dist/cli.js.map +1 -0
- package/dist/db.d.ts +39 -0
- package/dist/db.d.ts.map +1 -0
- package/dist/db.js +467 -0
- package/dist/db.js.map +1 -0
- package/package.json +50 -0
- package/template/README.md +24 -0
- package/template/gitignore +6 -0
- package/template/package.json +20 -0
- package/template/src/app.test.ts +8 -0
- package/template/src/app.ts +8 -0
- package/template/src/index.ts +5 -0
- package/template/tsconfig.json +16 -0
- package/template-isr/README.md +46 -0
- package/template-isr/backend.ts +12 -0
- package/template-isr/build.ts +23 -0
- package/template-isr/gitignore +7 -0
- package/template-isr/package.json +24 -0
- package/template-isr/routes/_404.tsx +10 -0
- package/template-isr/routes/_layout.tsx +18 -0
- package/template-isr/routes/index.tsx +34 -0
- package/template-isr/server.ts +56 -0
- package/template-isr/tsconfig.json +28 -0
- package/template-isr/worker.ts +52 -0
- package/template-isr/wrangler.toml +20 -0
- package/template-site/.dockerignore +14 -0
- package/template-site/Dockerfile +20 -0
- package/template-site/README.md +44 -0
- package/template-site/_worker.ts +17 -0
- package/template-site/backend.ts +12 -0
- package/template-site/build-bun.ts +27 -0
- package/template-site/build-deno.ts +25 -0
- package/template-site/build-node.ts +26 -0
- package/template-site/build-vercel.ts +45 -0
- package/template-site/build.ts +29 -0
- package/template-site/deno.json +7 -0
- package/template-site/framework.ts +6 -0
- package/template-site/gitignore +16 -0
- package/template-site/nifra.config.ts +9 -0
- package/template-site/package.json +37 -0
- package/template-site/routes/_404.tsx +20 -0
- package/template-site/routes/_layout.tsx +40 -0
- package/template-site/routes/index.tsx +53 -0
- package/template-site/server-bun.ts +35 -0
- package/template-site/server-deno.ts +38 -0
- package/template-site/server-node.ts +40 -0
- package/template-site/server-vercel.ts +17 -0
- package/template-site/tsconfig.json +37 -0
- package/template-site/wrangler.toml +4 -0
- package/template-site-preact/.dockerignore +14 -0
- package/template-site-preact/Dockerfile +20 -0
- package/template-site-preact/README.md +43 -0
- package/template-site-preact/_worker.ts +17 -0
- package/template-site-preact/backend.ts +12 -0
- package/template-site-preact/build-bun.ts +27 -0
- package/template-site-preact/build-deno.ts +25 -0
- package/template-site-preact/build-node.ts +26 -0
- package/template-site-preact/build-vercel.ts +45 -0
- package/template-site-preact/build.ts +29 -0
- package/template-site-preact/deno.json +7 -0
- package/template-site-preact/framework.ts +6 -0
- package/template-site-preact/gitignore +16 -0
- package/template-site-preact/nifra.config.ts +9 -0
- package/template-site-preact/package.json +34 -0
- package/template-site-preact/routes/_404.tsx +20 -0
- package/template-site-preact/routes/_layout.tsx +40 -0
- package/template-site-preact/routes/index.tsx +53 -0
- package/template-site-preact/server-bun.ts +35 -0
- package/template-site-preact/server-deno.ts +38 -0
- package/template-site-preact/server-node.ts +40 -0
- package/template-site-preact/server-vercel.ts +17 -0
- package/template-site-preact/tsconfig.json +38 -0
- package/template-site-preact/wrangler.toml +4 -0
- package/template-site-solid/.dockerignore +14 -0
- package/template-site-solid/Dockerfile +20 -0
- package/template-site-solid/README.md +43 -0
- package/template-site-solid/_worker.ts +17 -0
- package/template-site-solid/backend.ts +12 -0
- package/template-site-solid/build-bun.ts +33 -0
- package/template-site-solid/build-deno.ts +32 -0
- package/template-site-solid/build-node.ts +33 -0
- package/template-site-solid/build-vercel.ts +47 -0
- package/template-site-solid/build.ts +36 -0
- package/template-site-solid/deno.json +7 -0
- package/template-site-solid/framework.ts +6 -0
- package/template-site-solid/gitignore +16 -0
- package/template-site-solid/nifra.config.ts +14 -0
- package/template-site-solid/package.json +34 -0
- package/template-site-solid/routes/_404.tsx +20 -0
- package/template-site-solid/routes/_layout.tsx +39 -0
- package/template-site-solid/routes/index.tsx +53 -0
- package/template-site-solid/server-bun.ts +35 -0
- package/template-site-solid/server-deno.ts +38 -0
- package/template-site-solid/server-node.ts +40 -0
- package/template-site-solid/server-vercel.ts +17 -0
- package/template-site-solid/tsconfig.json +38 -0
- package/template-site-solid/wrangler.toml +4 -0
- package/template-site-svelte/.dockerignore +14 -0
- package/template-site-svelte/Dockerfile +20 -0
- package/template-site-svelte/README.md +45 -0
- package/template-site-svelte/_worker.ts +17 -0
- package/template-site-svelte/backend.ts +12 -0
- package/template-site-svelte/build-bun.ts +32 -0
- package/template-site-svelte/build-deno.ts +31 -0
- package/template-site-svelte/build-node.ts +32 -0
- package/template-site-svelte/build-vercel.ts +46 -0
- package/template-site-svelte/build.ts +35 -0
- package/template-site-svelte/deno.json +7 -0
- package/template-site-svelte/framework.ts +6 -0
- package/template-site-svelte/gitignore +16 -0
- package/template-site-svelte/nifra.config.ts +13 -0
- package/template-site-svelte/package.json +34 -0
- package/template-site-svelte/routes/_404.svelte +16 -0
- package/template-site-svelte/routes/_layout.svelte +35 -0
- package/template-site-svelte/routes/index.svelte +47 -0
- package/template-site-svelte/server-bun.ts +35 -0
- package/template-site-svelte/server-deno.ts +38 -0
- package/template-site-svelte/server-node.ts +40 -0
- package/template-site-svelte/server-vercel.ts +17 -0
- package/template-site-svelte/tsconfig.json +37 -0
- package/template-site-svelte/wrangler.toml +4 -0
- package/template-site-vue/.dockerignore +14 -0
- package/template-site-vue/Dockerfile +20 -0
- package/template-site-vue/README.md +45 -0
- package/template-site-vue/_worker.ts +17 -0
- package/template-site-vue/backend.ts +12 -0
- package/template-site-vue/build-bun.ts +37 -0
- package/template-site-vue/build-deno.ts +36 -0
- package/template-site-vue/build-node.ts +37 -0
- package/template-site-vue/build-vercel.ts +54 -0
- package/template-site-vue/build.ts +40 -0
- package/template-site-vue/deno.json +7 -0
- package/template-site-vue/framework.ts +6 -0
- package/template-site-vue/gitignore +16 -0
- package/template-site-vue/nifra.config.ts +19 -0
- package/template-site-vue/package.json +35 -0
- package/template-site-vue/routes/_404.vue +18 -0
- package/template-site-vue/routes/_layout.vue +40 -0
- package/template-site-vue/routes/index.vue +56 -0
- package/template-site-vue/server-bun.ts +35 -0
- package/template-site-vue/server-deno.ts +38 -0
- package/template-site-vue/server-node.ts +40 -0
- package/template-site-vue/server-vercel.ts +17 -0
- package/template-site-vue/tsconfig.json +37 -0
- package/template-site-vue/wrangler.toml +4 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Layout from "./_layout"
|
|
2
|
+
|
|
3
|
+
export const meta = { title: "Not found" }
|
|
4
|
+
|
|
5
|
+
// nifra's catch-all renders _404 without the layout chain, so it wraps itself in the root Layout.
|
|
6
|
+
export default function NotFound() {
|
|
7
|
+
return (
|
|
8
|
+
<Layout>
|
|
9
|
+
<section className="hero">
|
|
10
|
+
<h1>
|
|
11
|
+
<span className="grad">404</span>
|
|
12
|
+
</h1>
|
|
13
|
+
<p>That page doesn't exist.</p>
|
|
14
|
+
<a className="btn" href="/">
|
|
15
|
+
← Back home
|
|
16
|
+
</a>
|
|
17
|
+
</section>
|
|
18
|
+
</Layout>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ComponentChildren } from "preact"
|
|
2
|
+
|
|
3
|
+
const css = `
|
|
4
|
+
:root { --bg:#0a0a0f; --panel:#14141c; --border:#26263a; --fg:#e8e8f0; --muted:#9a9ab0; --accent:#7c5cff; --accent2:#00d4ff; }
|
|
5
|
+
* { box-sizing: border-box; } html { color-scheme: dark; }
|
|
6
|
+
body { margin:0; background:var(--bg); color:var(--fg); font:16px/1.6 ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif; -webkit-font-smoothing:antialiased; }
|
|
7
|
+
a { color:var(--accent2); text-decoration:none; } a:hover { text-decoration:underline; }
|
|
8
|
+
.wrap { max-width:840px; margin:0 auto; padding:0 24px; }
|
|
9
|
+
header.site { border-bottom:1px solid var(--border); } header.site .wrap { display:flex; align-items:center; justify-content:space-between; height:62px; }
|
|
10
|
+
.logo, .logo b { font-weight:800; font-size:20px; } .logo b { background:linear-gradient(90deg,var(--accent),var(--accent2)); -webkit-background-clip:text; background-clip:text; color:transparent; }
|
|
11
|
+
.hero { text-align:center; padding:80px 0 56px; }
|
|
12
|
+
.hero h1 { font-size:clamp(36px,6vw,56px); line-height:1.05; margin:0 0 16px; letter-spacing:-0.03em; }
|
|
13
|
+
.hero h1 .grad { background:linear-gradient(90deg,var(--accent),var(--accent2)); -webkit-background-clip:text; background-clip:text; color:transparent; }
|
|
14
|
+
.hero p { font-size:19px; color:var(--muted); max-width:560px; margin:0 auto 28px; }
|
|
15
|
+
.card { background:var(--panel); border:1px solid var(--border); border-radius:14px; padding:24px 28px; display:flex; align-items:center; justify-content:space-between; gap:24px; flex-wrap:wrap; }
|
|
16
|
+
.card h3 { margin:0 0 4px; } .card p { margin:0; color:var(--muted); font-size:14px; }
|
|
17
|
+
.count { font-size:34px; font-weight:800; font-variant-numeric:tabular-nums; min-width:44px; text-align:center; background:linear-gradient(90deg,var(--accent),var(--accent2)); -webkit-background-clip:text; background-clip:text; color:transparent; }
|
|
18
|
+
.btn { background:linear-gradient(90deg,var(--accent),var(--accent2)); color:#0a0a0f; font:inherit; font-weight:700; border:none; cursor:pointer; padding:11px 20px; border-radius:10px; }
|
|
19
|
+
footer.site { border-top:1px solid var(--border); color:var(--muted); font-size:14px; } footer.site .wrap { padding:24px; }
|
|
20
|
+
`.trim()
|
|
21
|
+
|
|
22
|
+
export default function Layout(props: { children?: ComponentChildren }) {
|
|
23
|
+
return (
|
|
24
|
+
<div id="app">
|
|
25
|
+
<style>{css}</style>
|
|
26
|
+
<header className="site">
|
|
27
|
+
<div className="wrap">
|
|
28
|
+
<a href="/" className="logo">
|
|
29
|
+
<b>nifra</b>
|
|
30
|
+
</a>
|
|
31
|
+
<a href="https://github.com">GitHub</a>
|
|
32
|
+
</div>
|
|
33
|
+
</header>
|
|
34
|
+
<main className="wrap">{props.children}</main>
|
|
35
|
+
<footer className="site">
|
|
36
|
+
<div className="wrap">Built with nifra</div>
|
|
37
|
+
</footer>
|
|
38
|
+
</div>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ActionArgs, LoaderArgs, LoaderData } from "@nifrajs/client"
|
|
2
|
+
import type { backend } from "../backend"
|
|
3
|
+
|
|
4
|
+
export const meta = {
|
|
5
|
+
title: "nifra site",
|
|
6
|
+
meta: [{ name: "description", content: "A nifra + Preact SSR site, deployable to every runtime." }],
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Loader runs on the server (in-process during SSR). The action handles the form POST; after a
|
|
10
|
+
// client submit the loader revalidates with no full reload (progressive enhancement).
|
|
11
|
+
export async function loader({ api }: LoaderArgs<typeof backend>) {
|
|
12
|
+
const res = await api.count.get()
|
|
13
|
+
return { count: res.data?.count ?? 0 }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function action({ api }: ActionArgs<typeof backend>) {
|
|
17
|
+
await api.count.post()
|
|
18
|
+
return { ok: true }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default function Home(props: { data: LoaderData<typeof loader> }) {
|
|
22
|
+
return (
|
|
23
|
+
<>
|
|
24
|
+
<section className="hero">
|
|
25
|
+
<h1>
|
|
26
|
+
Your nifra app,
|
|
27
|
+
<br />
|
|
28
|
+
<span className="grad">everywhere.</span>
|
|
29
|
+
</h1>
|
|
30
|
+
<p>
|
|
31
|
+
SSR + hydration, end-to-end types, Preact. One source — deploy to Cloudflare Pages, Node,
|
|
32
|
+
Deno, or Vercel Edge. Edit <code>routes/index.tsx</code> to begin.
|
|
33
|
+
</p>
|
|
34
|
+
</section>
|
|
35
|
+
|
|
36
|
+
<div className="card">
|
|
37
|
+
<div>
|
|
38
|
+
<h3>Live full-stack loop</h3>
|
|
39
|
+
<p>
|
|
40
|
+
Count is rendered by a typed <code>loader</code>, incremented by an <code>action</code>,
|
|
41
|
+
revalidated with no full reload.
|
|
42
|
+
</p>
|
|
43
|
+
</div>
|
|
44
|
+
<form method="post" style={{ display: "flex", alignItems: "center", gap: 16 }}>
|
|
45
|
+
<span className="count">{props.data.count}</span>
|
|
46
|
+
<button className="btn" type="submit">
|
|
47
|
+
increment →
|
|
48
|
+
</button>
|
|
49
|
+
</form>
|
|
50
|
+
</div>
|
|
51
|
+
</>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { inProcessClient } from "@nifrajs/client"
|
|
2
|
+
import { createWebApp } from "@nifrajs/web"
|
|
3
|
+
import { backend } from "./backend"
|
|
4
|
+
import { adapter } from "./framework"
|
|
5
|
+
import { clientEntry, manifest } from "./server-manifest"
|
|
6
|
+
|
|
7
|
+
const app = createWebApp({
|
|
8
|
+
adapter,
|
|
9
|
+
manifest,
|
|
10
|
+
clientEntry,
|
|
11
|
+
api: inProcessClient(backend),
|
|
12
|
+
title: "nifra site",
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
// Bun (nifra's flagship runtime): Bun.serve handles app.fetch; serve the client bundle (/assets/*)
|
|
16
|
+
// from disk with Bun.file. Assets live next to this file in the built dist-bun/ output.
|
|
17
|
+
const ASSETS = new URL("./assets/", import.meta.url)
|
|
18
|
+
const TYPES: Readonly<Record<string, string>> = { js: "text/javascript", css: "text/css" }
|
|
19
|
+
|
|
20
|
+
const server = Bun.serve({
|
|
21
|
+
port: Number(Bun.env.PORT ?? 3000),
|
|
22
|
+
async fetch(req) {
|
|
23
|
+
const { pathname } = new URL(req.url)
|
|
24
|
+
if (pathname.startsWith("/assets/")) {
|
|
25
|
+
const name = pathname.slice("/assets/".length)
|
|
26
|
+
if (!/^[A-Za-z0-9._-]+$/.test(name)) return new Response("bad request", { status: 400 })
|
|
27
|
+
const file = Bun.file(new URL(name, ASSETS))
|
|
28
|
+
if (!(await file.exists())) return new Response("not found", { status: 404 })
|
|
29
|
+
const ext = name.slice(name.lastIndexOf(".") + 1)
|
|
30
|
+
return new Response(file, { headers: { "content-type": TYPES[ext] ?? "application/octet-stream" } })
|
|
31
|
+
}
|
|
32
|
+
return app.fetch(req)
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
console.log(`nifra (Bun) → http://localhost:${server.port}`)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { inProcessClient } from "@nifrajs/client"
|
|
2
|
+
import { serve } from "@nifrajs/deno"
|
|
3
|
+
import { createWebApp } from "@nifrajs/web"
|
|
4
|
+
import { backend } from "./backend"
|
|
5
|
+
import { adapter } from "./framework"
|
|
6
|
+
import { clientEntry, manifest } from "./server-manifest"
|
|
7
|
+
|
|
8
|
+
const app = createWebApp({
|
|
9
|
+
adapter,
|
|
10
|
+
manifest,
|
|
11
|
+
clientEntry,
|
|
12
|
+
api: inProcessClient(backend),
|
|
13
|
+
title: "nifra site",
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
const ASSETS = new URL("./assets/", import.meta.url)
|
|
17
|
+
const TYPES: Readonly<Record<string, string>> = { js: "text/javascript", css: "text/css" }
|
|
18
|
+
|
|
19
|
+
await serve(
|
|
20
|
+
{
|
|
21
|
+
async fetch(req) {
|
|
22
|
+
const { pathname } = new URL(req.url)
|
|
23
|
+
if (pathname.startsWith("/assets/")) {
|
|
24
|
+
const name = pathname.slice("/assets/".length)
|
|
25
|
+
if (!/^[A-Za-z0-9._-]+$/.test(name)) return new Response("bad request", { status: 400 })
|
|
26
|
+
try {
|
|
27
|
+
const body = await Deno.readFile(new URL(name, ASSETS))
|
|
28
|
+
const ext = name.slice(name.lastIndexOf(".") + 1)
|
|
29
|
+
return new Response(body, { headers: { "content-type": TYPES[ext] ?? "application/octet-stream" } })
|
|
30
|
+
} catch {
|
|
31
|
+
return new Response("not found", { status: 404 })
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return app.fetch(req)
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
{ port: Number(Deno.env.get("PORT") ?? "3000") },
|
|
38
|
+
)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises"
|
|
2
|
+
import { inProcessClient } from "@nifrajs/client"
|
|
3
|
+
import { serve } from "@nifrajs/node"
|
|
4
|
+
import { createWebApp } from "@nifrajs/web"
|
|
5
|
+
import { backend } from "./backend"
|
|
6
|
+
import { adapter } from "./framework"
|
|
7
|
+
import { clientEntry, manifest } from "./server-manifest"
|
|
8
|
+
|
|
9
|
+
const app = createWebApp({
|
|
10
|
+
adapter,
|
|
11
|
+
manifest,
|
|
12
|
+
clientEntry,
|
|
13
|
+
api: inProcessClient(backend),
|
|
14
|
+
title: "nifra site",
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
// @nifrajs/node serves app.fetch only — so serve /assets/* (the client bundle) from disk here.
|
|
18
|
+
const ASSETS = new URL("./assets/", import.meta.url)
|
|
19
|
+
const TYPES: Readonly<Record<string, string>> = { js: "text/javascript", css: "text/css" }
|
|
20
|
+
|
|
21
|
+
await serve(
|
|
22
|
+
{
|
|
23
|
+
async fetch(req) {
|
|
24
|
+
const { pathname } = new URL(req.url)
|
|
25
|
+
if (pathname.startsWith("/assets/")) {
|
|
26
|
+
const name = pathname.slice("/assets/".length)
|
|
27
|
+
if (!/^[A-Za-z0-9._-]+$/.test(name)) return new Response("bad request", { status: 400 })
|
|
28
|
+
try {
|
|
29
|
+
const body = await readFile(new URL(name, ASSETS))
|
|
30
|
+
const ext = name.slice(name.lastIndexOf(".") + 1)
|
|
31
|
+
return new Response(body, { headers: { "content-type": TYPES[ext] ?? "application/octet-stream" } })
|
|
32
|
+
} catch {
|
|
33
|
+
return new Response("not found", { status: 404 })
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return app.fetch(req)
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
{ port: Number(process.env.PORT ?? 3000) },
|
|
40
|
+
)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { inProcessClient } from "@nifrajs/client"
|
|
2
|
+
import { createWebApp } from "@nifrajs/web"
|
|
3
|
+
import { backend } from "./backend"
|
|
4
|
+
import { adapter } from "./framework"
|
|
5
|
+
import { clientEntry, manifest } from "./server-manifest"
|
|
6
|
+
|
|
7
|
+
const app = createWebApp({
|
|
8
|
+
adapter,
|
|
9
|
+
manifest,
|
|
10
|
+
clientEntry,
|
|
11
|
+
api: inProcessClient(backend),
|
|
12
|
+
title: "nifra site",
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
// Vercel Edge Function — Vercel serves /assets/* from its CDN, so this only SSRs page routes.
|
|
16
|
+
export const config = { runtime: "edge" }
|
|
17
|
+
export default (req: Request): Response | Promise<Response> => app.fetch(req)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
7
|
+
"jsx": "react-jsx",
|
|
8
|
+
"jsxImportSource": "preact",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"noUncheckedIndexedAccess": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"noEmit": true,
|
|
13
|
+
"verbatimModuleSyntax": true
|
|
14
|
+
},
|
|
15
|
+
"include": ["**/*.ts", "**/*.tsx"],
|
|
16
|
+
"exclude": [
|
|
17
|
+
"node_modules",
|
|
18
|
+
"dist",
|
|
19
|
+
"dist-bun",
|
|
20
|
+
"dist-node",
|
|
21
|
+
"dist-deno",
|
|
22
|
+
"dist-vercel",
|
|
23
|
+
".nifra",
|
|
24
|
+
".wrangler",
|
|
25
|
+
".vercel",
|
|
26
|
+
"server-manifest.ts",
|
|
27
|
+
"server-bun.ts",
|
|
28
|
+
"server-node.ts",
|
|
29
|
+
"server-deno.ts",
|
|
30
|
+
"server-vercel.ts",
|
|
31
|
+
"_worker.ts",
|
|
32
|
+
"build.ts",
|
|
33
|
+
"build-bun.ts",
|
|
34
|
+
"build-node.ts",
|
|
35
|
+
"build-deno.ts",
|
|
36
|
+
"build-vercel.ts"
|
|
37
|
+
]
|
|
38
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# nifra on Node, containerized. Build with Bun (nifra's build toolchain), then run the self-contained
|
|
2
|
+
# bundle on a slim Node image — the final image carries no build tools or node_modules.
|
|
3
|
+
# docker build -t my-nifra-app .
|
|
4
|
+
# docker run -p 3000:3000 my-nifra-app
|
|
5
|
+
FROM oven/bun:1 AS build
|
|
6
|
+
WORKDIR /app
|
|
7
|
+
# Copy manifests first so the install layer caches across source-only changes.
|
|
8
|
+
COPY package.json bun.lock* ./
|
|
9
|
+
RUN bun install
|
|
10
|
+
COPY . .
|
|
11
|
+
RUN bun run build:node
|
|
12
|
+
|
|
13
|
+
FROM node:22-slim AS run
|
|
14
|
+
WORKDIR /app
|
|
15
|
+
ENV NODE_ENV=production
|
|
16
|
+
ENV PORT=3000
|
|
17
|
+
# build:node emits a self-contained server-bundle + the client assets it serves from disk.
|
|
18
|
+
COPY --from=build /app/dist-node ./dist-node
|
|
19
|
+
EXPOSE 3000
|
|
20
|
+
CMD ["node", "dist-node/server-node.js"]
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# nifra site (Solid)
|
|
2
|
+
|
|
3
|
+
A nifra + **Solid** SSR site — file-based routes, typed loaders/actions, hydration — that deploys to
|
|
4
|
+
**Bun, Node (Docker), Deno Deploy, Cloudflare Pages, and Vercel Edge from one source**. `app.fetch`
|
|
5
|
+
is Web-standard, so only the server entry + build target differ per platform.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
bun install
|
|
9
|
+
bun run dev # nifra dev → true-HMR dev server (Vite + nifra SSR) at http://localhost:3000
|
|
10
|
+
bun run preview # wrangler pages dev dist → preview the built Cloudflare bundle (run `bun run build` first)
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Routes are Solid function components (JSX, compiled by `solidBunPlugin`) under `routes/` — `index.tsx`
|
|
14
|
+
(landing + a live loader/action counter), `_layout.tsx` (chrome), `_404.tsx`. The frontend adapter is
|
|
15
|
+
one line in `framework.ts`; data lives behind `backend.ts`. Each `build*` script wires
|
|
16
|
+
`solidBunPlugin("dom")` for the client and `("ssr")` + the `solid` export condition for the server.
|
|
17
|
+
|
|
18
|
+
## Deploy — pick a target
|
|
19
|
+
|
|
20
|
+
| target | build | deploy |
|
|
21
|
+
| --- | --- | --- |
|
|
22
|
+
| **Bun** (flagship) | `bun run build:bun` | `bun run start` — any host |
|
|
23
|
+
| **Node** | `bun run build:node` | `docker build -t app . && docker run -p 3000:3000 app` (or `bun run start:node`) |
|
|
24
|
+
| **Deno Deploy** | `bun run build:deno` | `deployctl deploy --prod --entrypoint=dist-deno/server-deno.js` |
|
|
25
|
+
| **Cloudflare Pages** | `bun run build` | `bun run deploy:cf` |
|
|
26
|
+
| **Vercel Edge** | `bun run build:vercel` | `bun run deploy:vercel` |
|
|
27
|
+
|
|
28
|
+
nifra never enters your cloud credentials — it scaffolds the configs (`Dockerfile`, `deno.json`,
|
|
29
|
+
`wrangler.toml`, Vercel Build Output API); you run the vendor CLI.
|
|
30
|
+
|
|
31
|
+
## Structure
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
routes/ index.tsx (landing), _layout.tsx (chrome), _404.tsx
|
|
35
|
+
framework.ts the adapter (solidAdapter) — imported by the server entries (edge-bundlable)
|
|
36
|
+
nifra.config.ts the nifra CLI's dev/build config (adapter + clientModule + Solid plugins) — read by `nifra dev`
|
|
37
|
+
backend.ts your contract (loaders/actions call it in-process)
|
|
38
|
+
server-bun.ts Bun entry (Bun.serve) build-bun.ts → dist-bun/
|
|
39
|
+
_worker.ts Cloudflare Pages entry build.ts → dist/
|
|
40
|
+
server-node.ts Node entry (@nifrajs/node) build-node.ts → dist-node/ (Dockerfile)
|
|
41
|
+
server-deno.ts Deno entry (@nifrajs/deno) build-deno.ts → dist-deno/ (deno.json)
|
|
42
|
+
server-vercel.ts Vercel Edge function build-vercel.ts → .vercel/output/
|
|
43
|
+
```
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { inProcessClient } from "@nifrajs/client"
|
|
2
|
+
import { toFetchHandler } from "@nifrajs/core"
|
|
3
|
+
import { createWebApp } from "@nifrajs/web"
|
|
4
|
+
import { backend } from "./backend"
|
|
5
|
+
import { adapter } from "./framework"
|
|
6
|
+
import { clientEntry, manifest } from "./server-manifest"
|
|
7
|
+
|
|
8
|
+
const app = createWebApp({
|
|
9
|
+
adapter,
|
|
10
|
+
manifest,
|
|
11
|
+
clientEntry,
|
|
12
|
+
api: inProcessClient(backend),
|
|
13
|
+
title: "nifra site",
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
// Cloudflare Pages: _routes.json serves /assets/* statically; everything else hits this (SSR).
|
|
17
|
+
export default toFetchHandler(app)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { server } from "@nifrajs/core"
|
|
2
|
+
|
|
3
|
+
// Your backend contract — page loaders/actions call it in-process during SSR (no network). Replace
|
|
4
|
+
// the demo counter with real data (KV/D1/Postgres/…); on the edge, reach bindings via `c.env`.
|
|
5
|
+
let count = 0
|
|
6
|
+
|
|
7
|
+
export const backend = server()
|
|
8
|
+
.get("/count", () => ({ count }))
|
|
9
|
+
.post("/count", () => {
|
|
10
|
+
count += 1
|
|
11
|
+
return { count }
|
|
12
|
+
})
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Build for Bun (nifra's flagship runtime) → dist-bun/ (server-bun.js + client assets).
|
|
2
|
+
// `bun run build:bun`. Run: `bun dist-bun/server-bun.js`.
|
|
3
|
+
import { cpSync, mkdirSync, rmSync } from "node:fs"
|
|
4
|
+
import { buildClient, buildServer } from "@nifrajs/web/build"
|
|
5
|
+
import { solidBunPlugin } from "@nifrajs/web-solid"
|
|
6
|
+
|
|
7
|
+
const dir = import.meta.dir
|
|
8
|
+
const dist = `${dir}/dist-bun`
|
|
9
|
+
const define = { "process.env.NODE_ENV": '"production"' }
|
|
10
|
+
rmSync(dist, { recursive: true, force: true })
|
|
11
|
+
mkdirSync(`${dist}/assets`, { recursive: true })
|
|
12
|
+
|
|
13
|
+
const client = await buildClient({
|
|
14
|
+
routesDir: `${dir}/routes`,
|
|
15
|
+
outDir: `${dist}/assets`,
|
|
16
|
+
clientModule: "@nifrajs/web-solid/client",
|
|
17
|
+
plugins: [solidBunPlugin("dom")],
|
|
18
|
+
conditions: ["bun", "solid", "browser"],
|
|
19
|
+
define,
|
|
20
|
+
})
|
|
21
|
+
const { worker } = await buildServer({
|
|
22
|
+
routesDir: `${dir}/routes`,
|
|
23
|
+
serverEntry: `${dir}/server-bun.ts`,
|
|
24
|
+
outDir: `${dir}/.build-bun`,
|
|
25
|
+
target: "bun",
|
|
26
|
+
clientEntry: client.entry,
|
|
27
|
+
plugins: [solidBunPlugin("ssr")],
|
|
28
|
+
conditions: ["bun", "solid"],
|
|
29
|
+
define,
|
|
30
|
+
})
|
|
31
|
+
cpSync(worker, `${dist}/server-bun.js`)
|
|
32
|
+
rmSync(`${dir}/.build-bun`, { recursive: true, force: true })
|
|
33
|
+
console.log("Bun output → dist-bun (run: bun dist-bun/server-bun.js)")
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Build for Deno → dist-deno/ (server-deno.js + client assets). `bun run build:deno`.
|
|
2
|
+
// Run: `deno task start` (or deployctl). Deno runs the edge bundle (workerd/edge-light + solid).
|
|
3
|
+
import { cpSync, mkdirSync, rmSync } from "node:fs"
|
|
4
|
+
import { buildClient, buildServer } from "@nifrajs/web/build"
|
|
5
|
+
import { solidBunPlugin } from "@nifrajs/web-solid"
|
|
6
|
+
|
|
7
|
+
const dir = import.meta.dir
|
|
8
|
+
const dist = `${dir}/dist-deno`
|
|
9
|
+
const define = { "process.env.NODE_ENV": '"production"' }
|
|
10
|
+
rmSync(dist, { recursive: true, force: true })
|
|
11
|
+
mkdirSync(`${dist}/assets`, { recursive: true })
|
|
12
|
+
|
|
13
|
+
const client = await buildClient({
|
|
14
|
+
routesDir: `${dir}/routes`,
|
|
15
|
+
outDir: `${dist}/assets`,
|
|
16
|
+
clientModule: "@nifrajs/web-solid/client",
|
|
17
|
+
plugins: [solidBunPlugin("dom")],
|
|
18
|
+
conditions: ["bun", "solid", "browser"],
|
|
19
|
+
define,
|
|
20
|
+
})
|
|
21
|
+
const { worker } = await buildServer({
|
|
22
|
+
routesDir: `${dir}/routes`,
|
|
23
|
+
serverEntry: `${dir}/server-deno.ts`,
|
|
24
|
+
outDir: `${dir}/.build-deno`,
|
|
25
|
+
clientEntry: client.entry,
|
|
26
|
+
plugins: [solidBunPlugin("ssr")],
|
|
27
|
+
conditions: ["workerd", "edge-light", "solid", "browser"],
|
|
28
|
+
define,
|
|
29
|
+
})
|
|
30
|
+
cpSync(worker, `${dist}/server-deno.js`)
|
|
31
|
+
rmSync(`${dir}/.build-deno`, { recursive: true, force: true })
|
|
32
|
+
console.log("Deno output → dist-deno (run: deno run -A dist-deno/server-deno.js)")
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Build for Node → dist-node/ (server-node.js + client assets). `bun run build:node`.
|
|
2
|
+
// Run: `node dist-node/server-node.js` (or the Dockerfile). `node`+`solid` → solid-js/web's server build.
|
|
3
|
+
import { cpSync, mkdirSync, rmSync } from "node:fs"
|
|
4
|
+
import { buildClient, buildServer } from "@nifrajs/web/build"
|
|
5
|
+
import { solidBunPlugin } from "@nifrajs/web-solid"
|
|
6
|
+
|
|
7
|
+
const dir = import.meta.dir
|
|
8
|
+
const dist = `${dir}/dist-node`
|
|
9
|
+
const define = { "process.env.NODE_ENV": '"production"' }
|
|
10
|
+
rmSync(dist, { recursive: true, force: true })
|
|
11
|
+
mkdirSync(`${dist}/assets`, { recursive: true })
|
|
12
|
+
|
|
13
|
+
const client = await buildClient({
|
|
14
|
+
routesDir: `${dir}/routes`,
|
|
15
|
+
outDir: `${dist}/assets`,
|
|
16
|
+
clientModule: "@nifrajs/web-solid/client",
|
|
17
|
+
plugins: [solidBunPlugin("dom")],
|
|
18
|
+
conditions: ["bun", "solid", "browser"],
|
|
19
|
+
define,
|
|
20
|
+
})
|
|
21
|
+
const { worker } = await buildServer({
|
|
22
|
+
routesDir: `${dir}/routes`,
|
|
23
|
+
serverEntry: `${dir}/server-node.ts`,
|
|
24
|
+
outDir: `${dir}/.build-node`,
|
|
25
|
+
target: "node",
|
|
26
|
+
clientEntry: client.entry,
|
|
27
|
+
plugins: [solidBunPlugin("ssr")],
|
|
28
|
+
conditions: ["node", "solid"],
|
|
29
|
+
define,
|
|
30
|
+
})
|
|
31
|
+
cpSync(worker, `${dist}/server-node.js`)
|
|
32
|
+
rmSync(`${dir}/.build-node`, { recursive: true, force: true })
|
|
33
|
+
console.log("Node output → dist-node (run: node dist-node/server-node.js)")
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Build for Vercel, emitting Vercel's Build Output API v3 at .vercel/output/ so it deploys with no
|
|
2
|
+
// framework preset: `vercel deploy --prebuilt`.
|
|
3
|
+
import { cpSync, mkdirSync, rmSync, writeFileSync } from "node:fs"
|
|
4
|
+
import { buildClient, buildServer } from "@nifrajs/web/build"
|
|
5
|
+
import { solidBunPlugin } from "@nifrajs/web-solid"
|
|
6
|
+
|
|
7
|
+
const dir = import.meta.dir
|
|
8
|
+
const out = `${dir}/.vercel/output`
|
|
9
|
+
const fn = `${out}/functions/index.func`
|
|
10
|
+
const define = { "process.env.NODE_ENV": '"production"' }
|
|
11
|
+
rmSync(`${dir}/.vercel`, { recursive: true, force: true })
|
|
12
|
+
mkdirSync(`${out}/static/assets`, { recursive: true })
|
|
13
|
+
mkdirSync(fn, { recursive: true })
|
|
14
|
+
|
|
15
|
+
const client = await buildClient({
|
|
16
|
+
routesDir: `${dir}/routes`,
|
|
17
|
+
outDir: `${out}/static/assets`,
|
|
18
|
+
clientModule: "@nifrajs/web-solid/client",
|
|
19
|
+
plugins: [solidBunPlugin("dom")],
|
|
20
|
+
conditions: ["bun", "solid", "browser"],
|
|
21
|
+
define,
|
|
22
|
+
})
|
|
23
|
+
const { worker } = await buildServer({
|
|
24
|
+
routesDir: `${dir}/routes`,
|
|
25
|
+
serverEntry: `${dir}/server-vercel.ts`,
|
|
26
|
+
outDir: `${dir}/.build-vercel`,
|
|
27
|
+
clientEntry: client.entry,
|
|
28
|
+
plugins: [solidBunPlugin("ssr")],
|
|
29
|
+
conditions: ["workerd", "edge-light", "solid", "browser"],
|
|
30
|
+
define,
|
|
31
|
+
})
|
|
32
|
+
cpSync(worker, `${fn}/index.js`)
|
|
33
|
+
rmSync(`${dir}/.build-vercel`, { recursive: true, force: true })
|
|
34
|
+
|
|
35
|
+
writeFileSync(
|
|
36
|
+
`${fn}/.vc-config.json`,
|
|
37
|
+
`${JSON.stringify({ runtime: "edge", entrypoint: "index.js" }, null, 2)}\n`,
|
|
38
|
+
)
|
|
39
|
+
writeFileSync(
|
|
40
|
+
`${out}/config.json`,
|
|
41
|
+
`${JSON.stringify(
|
|
42
|
+
{ version: 3, routes: [{ handle: "filesystem" }, { src: "/(.*)", dest: "/index" }] },
|
|
43
|
+
null,
|
|
44
|
+
2,
|
|
45
|
+
)}\n`,
|
|
46
|
+
)
|
|
47
|
+
console.log("Vercel output → .vercel/output (deploy: vercel deploy --prebuilt)")
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Build for Cloudflare Pages → dist/ (_worker.js + _routes.json + client assets). `bun run build`.
|
|
2
|
+
// Solid: solidBunPlugin("dom") for the client, ("ssr") for the server + the `solid` export condition.
|
|
3
|
+
import { cpSync, mkdirSync, rmSync, writeFileSync } from "node:fs"
|
|
4
|
+
import { buildClient, buildServer } from "@nifrajs/web/build"
|
|
5
|
+
import { solidBunPlugin } from "@nifrajs/web-solid"
|
|
6
|
+
|
|
7
|
+
const dir = import.meta.dir
|
|
8
|
+
const dist = `${dir}/dist`
|
|
9
|
+
const define = { "process.env.NODE_ENV": '"production"' }
|
|
10
|
+
rmSync(dist, { recursive: true, force: true })
|
|
11
|
+
mkdirSync(`${dist}/assets`, { recursive: true })
|
|
12
|
+
|
|
13
|
+
const client = await buildClient({
|
|
14
|
+
routesDir: `${dir}/routes`,
|
|
15
|
+
outDir: `${dist}/assets`,
|
|
16
|
+
clientModule: "@nifrajs/web-solid/client",
|
|
17
|
+
plugins: [solidBunPlugin("dom")],
|
|
18
|
+
conditions: ["bun", "solid", "browser"],
|
|
19
|
+
define,
|
|
20
|
+
})
|
|
21
|
+
const { worker } = await buildServer({
|
|
22
|
+
routesDir: `${dir}/routes`,
|
|
23
|
+
serverEntry: `${dir}/_worker.ts`,
|
|
24
|
+
outDir: `${dir}/.build`,
|
|
25
|
+
clientEntry: client.entry,
|
|
26
|
+
plugins: [solidBunPlugin("ssr")],
|
|
27
|
+
conditions: ["workerd", "edge-light", "solid", "browser"],
|
|
28
|
+
define,
|
|
29
|
+
})
|
|
30
|
+
cpSync(worker, `${dist}/_worker.js`)
|
|
31
|
+
rmSync(`${dir}/.build`, { recursive: true, force: true })
|
|
32
|
+
writeFileSync(
|
|
33
|
+
`${dist}/_routes.json`,
|
|
34
|
+
`${JSON.stringify({ version: 1, include: ["/*"], exclude: ["/assets/*"] }, null, 2)}\n`,
|
|
35
|
+
)
|
|
36
|
+
console.log("Cloudflare Pages output → dist (deploy: wrangler pages deploy dist)")
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"tasks": {
|
|
3
|
+
"build": "bun run build-deno.ts",
|
|
4
|
+
"start": "deno run --allow-net --allow-read --allow-env dist-deno/server-deno.js"
|
|
5
|
+
},
|
|
6
|
+
"//": "Build with Bun (nifra's toolchain), run/deploy the self-contained bundle on Deno. Deploy to Deno Deploy: deployctl deploy --prod --entrypoint=dist-deno/server-deno.js"
|
|
7
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// The frontend adapter for this app. `create-nifra --framework <react|preact|vue|solid|svelte>` swaps
|
|
2
|
+
// this one line (and the routes + build config); every server entry imports the adapter from here, so
|
|
3
|
+
// they stay framework-agnostic.
|
|
4
|
+
import { solidAdapter } from "@nifrajs/web-solid"
|
|
5
|
+
|
|
6
|
+
export const adapter = solidAdapter
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
node_modules
|
|
2
|
+
dist
|
|
3
|
+
dist-bun
|
|
4
|
+
dist-node
|
|
5
|
+
dist-deno
|
|
6
|
+
.vercel
|
|
7
|
+
.build
|
|
8
|
+
.build-bun
|
|
9
|
+
.build-node
|
|
10
|
+
.build-deno
|
|
11
|
+
.build-vercel
|
|
12
|
+
.wrangler
|
|
13
|
+
# generated by buildServer next to the entry
|
|
14
|
+
server-manifest.ts
|
|
15
|
+
# generated by `nifra dev` (the Vite dev client entry) at the project root
|
|
16
|
+
.nifra-vite-entry.tsx
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// The nifra CLI's config — read by `nifra dev|build|start`. It's imported ONLY by the CLI (which runs on
|
|
2
|
+
// Bun), so it can eagerly import the Vite plugin + the Solid compile plugin — keeping them OUT of the
|
|
3
|
+
// edge worker bundle that `framework.ts` (the render-adapter source the entries import) must stay free
|
|
4
|
+
// of. Solid needs the `"solid"` resolve condition (routes solid-js to its source / JSX-dev build).
|
|
5
|
+
import { solidBunPlugin } from "@nifrajs/web-solid"
|
|
6
|
+
import solid from "vite-plugin-solid"
|
|
7
|
+
|
|
8
|
+
export { adapter } from "./framework"
|
|
9
|
+
export const clientModule = "@nifrajs/web-solid/client"
|
|
10
|
+
// `ssr: true` makes vite-plugin-solid emit hydratable client output, matching nifra's Bun SSR.
|
|
11
|
+
export const vitePlugins = [solid({ ssr: true })]
|
|
12
|
+
export const clientPlugins = [solidBunPlugin("dom")]
|
|
13
|
+
export const serverPlugins = [solidBunPlugin("ssr")]
|
|
14
|
+
export const conditions = ["solid"]
|