-
-
Notifications
You must be signed in to change notification settings - Fork 886
Expand file tree
/
Copy pathnitro.config.ts
More file actions
201 lines (199 loc) · 5.86 KB
/
Copy pathnitro.config.ts
File metadata and controls
201 lines (199 loc) · 5.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import { defineConfig } from "nitro";
import { dirname, resolve } from "node:path";
import { existsSync } from "node:fs";
export default defineConfig({
vercel: {
immutableStaticFiles: true,
functionRules: {
"/api/hello": {
maxDuration: 100,
},
"/api/echo": {
experimentalTriggers: [{ type: "queue/v2beta", topic: "orders" }],
},
"/rules/isr/**": {
regions: ["lhr1", "cdg1"],
},
},
},
compressPublicAssets: true,
compatibilityDate: "latest",
serverDir: "server",
builder: (process.env.NITRO_BUILDER as any) || "rolldown",
// @ts-expect-error
__vitePkg__: process.env.NITRO_VITE_PKG,
framework: { name: "nitro", version: "3.x" },
imports: {
presets: [
{
// TODO: move this to built-in preset
from: "scule",
imports: ["camelCase", "pascalCase", "kebabCase"],
},
],
},
sourcemap: true,
rollupConfig: {
output: {
sourcemapPathTransform: (relativeSourcePath, sourcemapPath) => {
const sourcemapDir = dirname(sourcemapPath);
const sourcePath = resolve(sourcemapDir, relativeSourcePath);
return existsSync(sourcePath) ? sourcePath : relativeSourcePath;
},
},
},
virtual: {
"#virtual-route": () => `export default () => new Response("Hello from virtual entry!")`,
},
handlers: [
{
route: "/api/test/*/foo",
handler: "./server/routes/api/hello.ts",
method: "GET",
},
{
route: "/api/hello2",
handler: "./server/routes/api/hello.ts",
middleware: true,
},
{
route: "/virtual",
handler: "#virtual-route",
},
],
devProxy: {
"/proxy/example": {
target: "https://icanhazip.com",
changeOrigin: true,
ignorePath: true,
},
},
traceDeps: ["@fixture"],
serverAssets: [
{
baseName: "files",
dir: "server/files",
},
],
ignore: ["routes/api/**/_*", "middleware/_ignored.ts", "routes/_*.ts", "**/_*.txt"],
runtimeConfig: {
dynamic: "initial",
url: "https://{{APP_DOMAIN}}",
},
publicAssets: [
{
baseURL: "build",
dir: "public/build",
maxAge: 3600,
},
],
tasks: {
"db:migrate": { description: "Migrate database" },
"db:seed": { description: "Seed database" },
},
errorHandler: "error.ts",
routeRules: {
"/api/param/prerender4": { prerender: true },
"/api/param/prerender2": { prerender: false },
"/rules/headers": { headers: { "cache-control": "s-maxage=60" } },
"/rules/cors": {
cors: true,
headers: { "access-control-allow-methods": "GET" },
},
"/rules/dynamic": { cache: false, isr: false },
"/rules/redirect": { redirect: "/base" },
"/rules/isr/**": { isr: { allowQuery: ["q"] } },
"/rules/isr-ttl/**": { isr: 60 },
"/rules/swr/**": { swr: true },
"/rules/swr-ttl/**": { swr: 60 },
"/rules/redirect/obj": {
redirect: { to: "https://nitro.build/", status: 308 },
},
"/rules/redirect/wildcard/**": { redirect: "https://nitro.build/**" },
"/rules/redirect/legacy/**": { redirect: "/**" },
"/rules/nested/**": { redirect: "/base", headers: { "x-test": "test" } },
"/rules/nested/override": { redirect: { to: "/other" } },
"/rules/_/noncached/cached": { swr: true },
"/rules/_/noncached/**": { swr: false, cache: false, isr: false },
"/rules/_/cached/noncached": { cache: false, swr: false, isr: false },
"/rules/_/cached/**": { swr: true },
"/api/proxy/**": { proxy: "/api/echo" },
"/rules/proxy/legacy/**": { proxy: "/api/wildcard/**" },
"/cdn/**": { proxy: "https://cdn.jsdelivr.net/**" },
"/rules/basic-auth/**": {
basicAuth: { username: "admin", password: "secret", realm: "Secure Area" },
},
"/rules/basic-auth/no-auth/**": { basicAuth: false },
"/rules/ba-redirect/**": { redirect: "/base" },
"/rules/ba-redirect/secure/**": {
basicAuth: { username: "admin", password: "secret", realm: "Secure Area" },
},
"/rules/ba-proxy/**": { proxy: "/api/echo" },
"/rules/ba-proxy/secure/**": {
basicAuth: { username: "admin", password: "secret", realm: "Secure Area" },
},
"/rules/ba-nested/**": {
basicAuth: { username: "broad", password: "secret", realm: "Broad Area" },
},
"/rules/ba-nested/admin/**": {
basicAuth: { username: "admin", password: "secret", realm: "Admin Area" },
},
"/rules/ba-off/**": {
basicAuth: { username: "admin", password: "secret", realm: "Off Area" },
},
"/rules/ba-off/*": { basicAuth: false },
"/rules/ba-strip/**": {
basicAuth: { username: "admin", password: "secret", realm: "Strip Area" },
},
"/rules/ba-strip/off/**": { basicAuth: false },
"/ba-single/*": {
basicAuth: { username: "admin", password: "secret", realm: "Secure Area" },
},
// Method-scoped route rule: the `"METHOD /path"` key only applies to that method.
"POST /rules/method-scoped/**": {
basicAuth: { username: "admin", password: "secret", realm: "Secure Area" },
},
"/single-headers/*": { headers: { "x-single": "single" } },
"**": { headers: { "x-test": "test" } },
},
prerender: {
crawlLinks: true,
ignore: [
// '/api/param/'
],
routes: ["/prerender", "/prerender-custom.html", "/404"],
},
experimental: {
openAPI: true,
asyncContext: true,
envExpansion: true,
database: true,
tasks: true,
},
scheduledTasks: {
"* * * * *": "test",
},
cloudflare: {
pages: {
routes: {
include: ["/*"],
exclude: ["/blog/static/*", "/cf-pages-exclude/*"],
},
},
wrangler: {
compatibility_date: "2024-01-01",
},
},
typescript: {
generateRuntimeConfigTypes: true,
generateTsConfig: true,
},
openAPI: {
production: "prerender",
meta: {
title: "Nitro Test Fixture",
description: "Nitro Test Fixture API",
version: "2.0",
},
},
});