eddev 2.3.30 → 2.4.0-beta.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/dist/app/entry/ssr-root-client.d.ts +0 -2
- package/dist/app/entry/ssr-root-client.d.ts.map +1 -1
- package/dist/app/lib/blocks/block-debugger.d.ts.map +1 -1
- package/dist/app/lib/blocks/block-debugger.js +19 -2
- package/dist/app/lib/devtools/components/panels/StructurePanel.js +1 -1
- package/dist/app/lib/routing/components/BrowserRouter.d.ts.map +1 -1
- package/dist/app/lib/routing/components/BrowserRouter.js +10 -7
- package/dist/app/server/assets.d.ts +45 -0
- package/dist/app/server/assets.d.ts.map +1 -0
- package/dist/app/server/assets.js +15 -0
- package/dist/app/server/index.d.ts +4 -0
- package/dist/app/server/index.d.ts.map +1 -1
- package/dist/app/server/index.js +3 -0
- package/dist/app/server/proxy-wp-admin.d.ts +6 -2
- package/dist/app/server/proxy-wp-admin.d.ts.map +1 -1
- package/dist/app/server/proxy-wp-admin.js +29 -57
- package/dist/app/server/render-ssr-page.d.ts +2 -6
- package/dist/app/server/render-ssr-page.d.ts.map +1 -1
- package/dist/app/server/render-ssr-page.js +9 -8
- package/dist/app/server/rpc-handler.d.ts +14 -0
- package/dist/app/server/rpc-handler.d.ts.map +1 -0
- package/dist/app/server/rpc-handler.js +63 -0
- package/dist/app/server/server-app.d.ts +22 -0
- package/dist/app/server/server-app.d.ts.map +1 -0
- package/dist/app/server/server-app.js +186 -0
- package/dist/app/server/server-context.d.ts +5 -5
- package/dist/app/server/server-context.d.ts.map +1 -1
- package/dist/app/server/server-context.js +9 -8
- package/dist/app/server/utils/fetch-origin.d.ts +13 -0
- package/dist/app/server/utils/fetch-origin.d.ts.map +1 -0
- package/dist/app/server/utils/fetch-origin.js +21 -0
- package/dist/app/server/utils/request.d.ts +20 -0
- package/dist/app/server/utils/request.d.ts.map +1 -0
- package/dist/app/server/utils/request.js +60 -0
- package/dist/node/cli/cli-worker.d.ts +10 -6
- package/dist/node/cli/cli-worker.d.ts.map +1 -1
- package/dist/node/cli/cli-worker.js +7 -14
- package/dist/node/cli/cli.js +37 -43
- package/dist/node/cli/display/CLIApp.d.ts +2 -4
- package/dist/node/cli/display/CLIApp.d.ts.map +1 -1
- package/dist/node/cli/display/CLIApp.js +2 -3
- package/dist/node/cli/version.d.ts +1 -1
- package/dist/node/cli/version.d.ts.map +1 -1
- package/dist/node/cli/version.js +1 -1
- package/dist/node/compiler/app-codegen.d.ts +18 -0
- package/dist/node/compiler/app-codegen.d.ts.map +1 -0
- package/dist/node/compiler/app-codegen.js +473 -0
- package/dist/node/compiler/build-serverless.d.ts +16 -0
- package/dist/node/compiler/build-serverless.d.ts.map +1 -0
- package/dist/node/compiler/build-serverless.js +40 -0
- package/dist/node/compiler/bundler.spa.d.ts +33 -0
- package/dist/node/compiler/bundler.spa.d.ts.map +1 -0
- package/dist/node/compiler/bundler.spa.js +59 -0
- package/dist/node/compiler/dev-css-links.d.ts +25 -0
- package/dist/node/compiler/dev-css-links.d.ts.map +1 -0
- package/dist/node/compiler/dev-css-links.js +87 -0
- package/dist/node/compiler/dev-server.d.ts +2 -0
- package/dist/node/compiler/dev-server.d.ts.map +1 -1
- package/dist/node/compiler/dev-server.js +46 -61
- package/dist/node/compiler/get-vite-config.d.ts +37 -6
- package/dist/node/compiler/get-vite-config.d.ts.map +1 -1
- package/dist/node/compiler/get-vite-config.js +113 -121
- package/dist/node/compiler/serverless-app.d.ts +35 -0
- package/dist/node/compiler/serverless-app.d.ts.map +1 -0
- package/dist/node/compiler/serverless-app.js +332 -0
- package/dist/node/compiler/transforms/block-meta.d.ts +10 -0
- package/dist/node/compiler/transforms/block-meta.d.ts.map +1 -0
- package/dist/node/compiler/transforms/block-meta.js +27 -0
- package/dist/node/compiler/transforms/component-names.d.ts +19 -0
- package/dist/node/compiler/transforms/component-names.d.ts.map +1 -0
- package/dist/node/compiler/transforms/component-names.js +45 -0
- package/dist/node/compiler/transforms/index.d.ts +36 -0
- package/dist/node/compiler/transforms/index.d.ts.map +1 -0
- package/dist/node/compiler/transforms/index.js +80 -0
- package/dist/node/compiler/transforms/types.d.ts +48 -0
- package/dist/node/compiler/transforms/types.d.ts.map +1 -0
- package/dist/node/compiler/transforms/types.js +1 -0
- package/dist/node/project/config.d.ts +1 -1
- package/dist/node/project/config.d.ts.map +1 -1
- package/dist/node/project/config.js +1 -1
- package/dist/node/project/env.js +1 -1
- package/dist/node/project/project-log.d.ts +7 -0
- package/dist/node/project/project-log.d.ts.map +1 -0
- package/dist/node/project/project-log.js +6 -0
- package/dist/node/project/project.d.ts +2 -2
- package/dist/node/project/project.d.ts.map +1 -1
- package/dist/node/project/project.js +3 -3
- package/dist/node/utils/fs.d.ts +70 -69
- package/dist/node/utils/fs.d.ts.map +1 -1
- package/dist/node/utils/http-to-https-redirect.d.ts +10 -0
- package/dist/node/utils/http-to-https-redirect.d.ts.map +1 -0
- package/dist/node/utils/http-to-https-redirect.js +49 -0
- package/dist/node/utils/self-signed-cert.d.ts.map +1 -1
- package/dist/node/utils/self-signed-cert.js +13 -0
- package/package.json +12 -13
- package/skills/eddev/docs/devtool/cli.mdx +10 -8
- package/tsconfig.node.json +17 -5
- package/types.env.d.ts +1 -1
- package/dist/node/compiler/build-vinxi.d.ts +0 -9
- package/dist/node/compiler/build-vinxi.d.ts.map +0 -1
- package/dist/node/compiler/build-vinxi.js +0 -39
- package/dist/node/compiler/bundler.admin.d.ts +0 -14
- package/dist/node/compiler/bundler.admin.d.ts.map +0 -1
- package/dist/node/compiler/bundler.admin.js +0 -37
- package/dist/node/compiler/bundler.frontend.d.ts +0 -15
- package/dist/node/compiler/bundler.frontend.d.ts.map +0 -1
- package/dist/node/compiler/bundler.frontend.js +0 -51
- package/dist/node/compiler/vinxi-app.d.ts +0 -23
- package/dist/node/compiler/vinxi-app.d.ts.map +0 -1
- package/dist/node/compiler/vinxi-app.js +0 -261
- package/dist/node/compiler/vinxi-codegen.d.ts +0 -13
- package/dist/node/compiler/vinxi-codegen.d.ts.map +0 -1
- package/dist/node/compiler/vinxi-codegen.js +0 -764
|
@@ -1,764 +0,0 @@
|
|
|
1
|
-
import { camelCase, pascalCase } from "change-case-all";
|
|
2
|
-
import { code, imp } from "ts-poet";
|
|
3
|
-
import { ProjectEnvUtils } from "../project/env.js";
|
|
4
|
-
import { FSCodegen } from "../utils/fs-codegen.js";
|
|
5
|
-
import { getCacheConfig } from "./cache-config.js";
|
|
6
|
-
export function getVinxiFolder(opts) {
|
|
7
|
-
return (opts.mode === "development" ? "dev" : "prod") + (opts.serverless ? "" : "-spa");
|
|
8
|
-
}
|
|
9
|
-
export async function runVinxiCodegen(opts) {
|
|
10
|
-
const codegen = createVinxiCodegen(opts);
|
|
11
|
-
await codegen.run();
|
|
12
|
-
codegen.stop();
|
|
13
|
-
}
|
|
14
|
-
export function createVinxiCodegen(opts) {
|
|
15
|
-
const project = opts.project;
|
|
16
|
-
const folder = ".eddev/" + getVinxiFolder(opts);
|
|
17
|
-
const codegen = new FSCodegen(opts.project, {
|
|
18
|
-
outDir: folder,
|
|
19
|
-
});
|
|
20
|
-
if (opts.serverless) {
|
|
21
|
-
codegen.registerFile({
|
|
22
|
-
name: "context.ts",
|
|
23
|
-
generate: async () => {
|
|
24
|
-
const args = {
|
|
25
|
-
dev: opts.mode === "development",
|
|
26
|
-
origin: project.origin,
|
|
27
|
-
replaceUrls: {
|
|
28
|
-
from: project.origin,
|
|
29
|
-
to: opts.endpoint ?? "",
|
|
30
|
-
prefixes: [
|
|
31
|
-
{ prefix: "/wp-content/uploads", replace: project.config?.serverless.uploads === "remote" },
|
|
32
|
-
{ prefix: "/wp-content/plugins", replace: project.config?.serverless.plugins === "remote" },
|
|
33
|
-
],
|
|
34
|
-
},
|
|
35
|
-
rpcBases: (await project.serverRoutes.get()).bases ?? [],
|
|
36
|
-
config: project.config,
|
|
37
|
-
cacheConfig: getCacheConfig(project.origin, project.config),
|
|
38
|
-
};
|
|
39
|
-
return code /* tsx */ `
|
|
40
|
-
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
41
|
-
import { ServerContext } from "eddev/server"
|
|
42
|
-
import { getManifest } from "vinxi/manifest"
|
|
43
|
-
import { apiConfig } from 'eddev/hooks'
|
|
44
|
-
|
|
45
|
-
ServerContext.setRuntime({
|
|
46
|
-
getManifest
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
export const serverContext = new ServerContext({${Object.entries(args)
|
|
50
|
-
.map(([key, value]) => `${key}: ${JSON.stringify(value)}`)
|
|
51
|
-
.join(",\n")}
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
apiConfig.apiKey = ${JSON.stringify(ProjectEnvUtils.getSafe("SITE_API_KEY") ?? "")}
|
|
55
|
-
`.toString();
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
if (opts.serverless) {
|
|
60
|
-
codegen.registerFile({
|
|
61
|
-
name: "react-shim.js",
|
|
62
|
-
generate: code /* tsx */ `
|
|
63
|
-
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
64
|
-
import React from "react"
|
|
65
|
-
import ReactDOM from "react-dom/client"
|
|
66
|
-
Object.assign(React, window.React)
|
|
67
|
-
Object.assign(ReactDOM, window.ReactDOM)
|
|
68
|
-
`,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
if (opts.serverless) {
|
|
72
|
-
// codegen.registerFile({
|
|
73
|
-
// name: "manifest/extra-routes.ts",
|
|
74
|
-
// generate: code/* tsx */ `
|
|
75
|
-
// import { createRouter, eventHandler, getRouterParam, getQuery, getWebRequest, getRequestHeaders } from "vinxi/http"
|
|
76
|
-
// import { serverContext } from "./context.js"
|
|
77
|
-
// export const routes = [
|
|
78
|
-
// {
|
|
79
|
-
// pattern: '/test1',
|
|
80
|
-
// handler: () => import('../../../test.ts')
|
|
81
|
-
// }
|
|
82
|
-
// ]
|
|
83
|
-
// export default eventHandler((event) => {
|
|
84
|
-
// routes
|
|
85
|
-
// })
|
|
86
|
-
// `,
|
|
87
|
-
// })
|
|
88
|
-
}
|
|
89
|
-
codegen.registerFile({
|
|
90
|
-
name: "entry.admin.tsx",
|
|
91
|
-
generate: () => {
|
|
92
|
-
return code /* tsx */ `
|
|
93
|
-
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
94
|
-
${opts.serverless ? `import "./react-shim.js"` : ""}
|
|
95
|
-
${opts.serverless ? `import "vinxi/client"` : ""}
|
|
96
|
-
import "../../${project.cssEntryFile}"
|
|
97
|
-
import "./manifest/admin"
|
|
98
|
-
import "./manifest/blocks"
|
|
99
|
-
import "./manifest/styles"
|
|
100
|
-
import bootAdmin from "eddev/_internal/boot-admin.js"
|
|
101
|
-
|
|
102
|
-
bootAdmin()
|
|
103
|
-
|
|
104
|
-
if (import.meta.hot) {
|
|
105
|
-
import.meta.hot.on('vite:beforeFullReload', () => {
|
|
106
|
-
throw '(skipping full reload in editor)';
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
`;
|
|
111
|
-
},
|
|
112
|
-
});
|
|
113
|
-
codegen.registerFile({
|
|
114
|
-
name: "entry.client.tsx",
|
|
115
|
-
generate: () => {
|
|
116
|
-
if (opts.serverless) {
|
|
117
|
-
/**
|
|
118
|
-
* Client entry for SSR mode
|
|
119
|
-
*/
|
|
120
|
-
return code /* tsx */ `
|
|
121
|
-
/// <reference types="vinxi/types/client" />
|
|
122
|
-
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
123
|
-
/**
|
|
124
|
-
* SSR-mode frontend entry.
|
|
125
|
-
* Hydrates the main app, including the html/head/body elements.
|
|
126
|
-
* Also ensures that the assets used during SSR are loaded.
|
|
127
|
-
*/
|
|
128
|
-
import "vinxi/client"
|
|
129
|
-
import "../../${project.cssEntryFile}"
|
|
130
|
-
import "./manifest/blocks"
|
|
131
|
-
import "./manifest/views"
|
|
132
|
-
|
|
133
|
-
import * as React from "react"
|
|
134
|
-
import { Root, hydrateRoot } from "react-dom/client"
|
|
135
|
-
import { SSRClientRoot } from "eddev/_internal/ssr-root-client.js"
|
|
136
|
-
import { getManifest } from "vinxi/manifest"
|
|
137
|
-
import { createAssets } from "@vinxi/react"
|
|
138
|
-
import { devToolsStore } from 'eddev/devtools'
|
|
139
|
-
|
|
140
|
-
${process.env.VERCEL_SKEW_PROTECTION_ENABLED &&
|
|
141
|
-
code /* tsx*/ `
|
|
142
|
-
// Skew protection
|
|
143
|
-
const updateSkewCookie = () => {
|
|
144
|
-
document.cookie = "__vdpl=${process.env.VERCEL_DEPLOYMENT_ID}; expires=" + new Date(Date.now() + 24 * 60 * 60 * 1000).toUTCString() + "; path=/"
|
|
145
|
-
}
|
|
146
|
-
window.onfocus = updateSkewCookie
|
|
147
|
-
updateSkewCookie()
|
|
148
|
-
`}
|
|
149
|
-
|
|
150
|
-
// Set up a dynamic entry which will load the configured tailwind manifest
|
|
151
|
-
devToolsStore.loadTailwindConfig = () => import('./manifest/tailwind-config.js')
|
|
152
|
-
|
|
153
|
-
// Create the asset renderer, which will ensure scripts/styles are mounted correctly
|
|
154
|
-
function getAssets() {
|
|
155
|
-
const Assets = createAssets(getManifest("client").handler, getManifest("client"))
|
|
156
|
-
return <React.Suspense><Assets /></React.Suspense>
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
window.$reactRoot =
|
|
160
|
-
window.$reactRoot ||
|
|
161
|
-
hydrateRoot(
|
|
162
|
-
document.getElementById('root')!,
|
|
163
|
-
<React.Suspense><SSRClientRoot assets={getAssets()} metaTags={window._PAGE_DATA?.meta?.head} /></React.Suspense>,
|
|
164
|
-
{
|
|
165
|
-
identifierPrefix: "ed",
|
|
166
|
-
}
|
|
167
|
-
)
|
|
168
|
-
|
|
169
|
-
if (import.meta.hot) {
|
|
170
|
-
import.meta.hot.accept((mod) => {
|
|
171
|
-
if (mod) {
|
|
172
|
-
const app = <React.Suspense><SSRClientRoot assets={getAssets()} metaTags={window._PAGE_DATA?.meta?.head} /></React.Suspense>
|
|
173
|
-
window.$reactRoot?.render(app)
|
|
174
|
-
}
|
|
175
|
-
})
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
declare global {
|
|
179
|
-
interface Window {
|
|
180
|
-
$reactRoot?: Root
|
|
181
|
-
_PAGE_DATA: any
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
`;
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
return code /* tsx */ `
|
|
189
|
-
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
190
|
-
/**
|
|
191
|
-
* SPA-mode frontend entry.
|
|
192
|
-
* Renders the main app into the empty <div id='root'> element, and expects window._PAGE_DATA to be set.
|
|
193
|
-
*/
|
|
194
|
-
import "./manifest/blocks"
|
|
195
|
-
import "./manifest/views"
|
|
196
|
-
import "../../${project.cssEntryFile}"
|
|
197
|
-
import { devToolsStore } from 'eddev/devtools'
|
|
198
|
-
import { createRoot } from "react-dom/client"
|
|
199
|
-
import { SPARoot } from "eddev/_internal/spa-root.js"
|
|
200
|
-
import * as React from "react"
|
|
201
|
-
|
|
202
|
-
devToolsStore.loadTailwindConfig = () => import('./manifest/tailwind-config')
|
|
203
|
-
|
|
204
|
-
createRoot(document.getElementById("root")!).render(<React.Suspense><SPARoot /></React.Suspense>)
|
|
205
|
-
`;
|
|
206
|
-
}
|
|
207
|
-
},
|
|
208
|
-
});
|
|
209
|
-
if (opts.serverless) {
|
|
210
|
-
codegen.registerFile({
|
|
211
|
-
name: "handler.bypass.ts",
|
|
212
|
-
generate: code /* tsx */ `
|
|
213
|
-
/// <reference types="vinxi/types/server" />
|
|
214
|
-
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
215
|
-
import { invalidateByTag } from '@vercel/functions';
|
|
216
|
-
import { createRouter, eventHandler, getCookie, getHeader, setCookie } from "vinxi/http"
|
|
217
|
-
|
|
218
|
-
const BYPASS_TOKEN = process.env.VERCEL_BYPASS_TOKEN
|
|
219
|
-
const COOKIE_NAME = "__prerender_bypass"
|
|
220
|
-
|
|
221
|
-
const router = createRouter()
|
|
222
|
-
.get(
|
|
223
|
-
"/enable",
|
|
224
|
-
eventHandler(async (event) => {
|
|
225
|
-
if (!BYPASS_TOKEN) return false
|
|
226
|
-
|
|
227
|
-
setCookie(event, COOKIE_NAME, BYPASS_TOKEN, {
|
|
228
|
-
expires: new Date(Date.now() + 1000 * 60 * 60 * 24),
|
|
229
|
-
})
|
|
230
|
-
|
|
231
|
-
return true
|
|
232
|
-
}),
|
|
233
|
-
)
|
|
234
|
-
.get(
|
|
235
|
-
"/disable",
|
|
236
|
-
eventHandler(async (event) => {
|
|
237
|
-
setCookie(event, COOKIE_NAME, "")
|
|
238
|
-
|
|
239
|
-
return true
|
|
240
|
-
}),
|
|
241
|
-
)
|
|
242
|
-
.get(
|
|
243
|
-
"/check",
|
|
244
|
-
eventHandler(async (event) => {
|
|
245
|
-
const cookie = getCookie(event, COOKIE_NAME)
|
|
246
|
-
|
|
247
|
-
if (cookie === BYPASS_TOKEN) {
|
|
248
|
-
return true
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
return false
|
|
252
|
-
})
|
|
253
|
-
)
|
|
254
|
-
.get(
|
|
255
|
-
"/purge",
|
|
256
|
-
eventHandler(async (event) => {
|
|
257
|
-
|
|
258
|
-
if (getHeader(event, "x-prerender-revalidate") === BYPASS_TOKEN) {
|
|
259
|
-
return await invalidateByTag('data');
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
return false
|
|
263
|
-
}),
|
|
264
|
-
)
|
|
265
|
-
export default router.handler
|
|
266
|
-
`,
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
if (opts.serverless) {
|
|
270
|
-
codegen.registerFile({
|
|
271
|
-
name: "handler.ssr-page.ts",
|
|
272
|
-
generate: code /* tsx */ `
|
|
273
|
-
/// <reference types="vinxi/types/server" />
|
|
274
|
-
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
275
|
-
import "../../${project.cssEntryFile}"
|
|
276
|
-
import "./manifest/blocks.js"
|
|
277
|
-
import "./manifest/styles.js"
|
|
278
|
-
import "./manifest/views.js"
|
|
279
|
-
import "./context.js"
|
|
280
|
-
import { proxyWpAdmin, renderPage, renderPageForIndexing, ServerContext } from "eddev/server"
|
|
281
|
-
import {
|
|
282
|
-
createRouter,
|
|
283
|
-
eventHandler,
|
|
284
|
-
getQuery,
|
|
285
|
-
getRequestHeaders,
|
|
286
|
-
getRequestURL,
|
|
287
|
-
getRouterParam,
|
|
288
|
-
getWebRequest,
|
|
289
|
-
getCookie,
|
|
290
|
-
setCookie
|
|
291
|
-
} from "vinxi/http"
|
|
292
|
-
import { handleRPC } from "./rpc.js"
|
|
293
|
-
import { serverContext } from "./context.js"
|
|
294
|
-
import { getManifest } from "vinxi/manifest"
|
|
295
|
-
import { inspect } from "node:util"
|
|
296
|
-
import { withTrailingSlash } from 'ufo'
|
|
297
|
-
import { viewManifestReader, blockManifestReader } from 'eddev/_internal'
|
|
298
|
-
|
|
299
|
-
const router = createRouter()
|
|
300
|
-
.get(
|
|
301
|
-
"/_data/route/",
|
|
302
|
-
eventHandler(async (event) => {
|
|
303
|
-
const id = "/"
|
|
304
|
-
const url = getRequestURL(event)
|
|
305
|
-
|
|
306
|
-
return await serverContext.fetchRouteData({ pathname: id, newOrigin: url.origin, bypass: serverContext.shouldBypass(event) })
|
|
307
|
-
}),
|
|
308
|
-
)
|
|
309
|
-
.get(
|
|
310
|
-
"/_data/route/**:name",
|
|
311
|
-
eventHandler(async (event) => {
|
|
312
|
-
const id = "/" + getRouterParam(event, "name")
|
|
313
|
-
const url = getRequestURL(event)
|
|
314
|
-
|
|
315
|
-
return await serverContext.fetchRouteData({ pathname: id, newOrigin: url.origin, bypass: serverContext.shouldBypass(event) })
|
|
316
|
-
}),
|
|
317
|
-
)
|
|
318
|
-
.get(
|
|
319
|
-
"/_data/query/**:name",
|
|
320
|
-
eventHandler(async (event) => {
|
|
321
|
-
const url = getRequestURL(event)
|
|
322
|
-
|
|
323
|
-
const queryPath = event.path.replace("/_data/query", "")
|
|
324
|
-
const paramSeparator = queryPath.indexOf("=")
|
|
325
|
-
const id = paramSeparator === -1 ? queryPath : queryPath.slice(0, paramSeparator)
|
|
326
|
-
const paramString = paramSeparator === -1 ? undefined : queryPath.slice(paramSeparator + 1)
|
|
327
|
-
|
|
328
|
-
let params = {}
|
|
329
|
-
try {
|
|
330
|
-
params =
|
|
331
|
-
typeof paramString === "string" && paramString.length
|
|
332
|
-
? JSON.parse(decodeURIComponent(paramString.replace(/\\/$/, "")))
|
|
333
|
-
: {}
|
|
334
|
-
} catch (e) {
|
|
335
|
-
throw new Error("Invalid query parameters")
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
return await serverContext.fetchNamedQuery({ name: id, newOrigin: url.origin, params: params, headers: getRequestHeaders(event), bypass: serverContext.shouldBypass(event) })
|
|
339
|
-
}),
|
|
340
|
-
)
|
|
341
|
-
.get(
|
|
342
|
-
"/_data/manifest/**:input",
|
|
343
|
-
eventHandler(async (event) => {
|
|
344
|
-
const manifest = getManifest("client")
|
|
345
|
-
const id = getRouterParam(event, "input")
|
|
346
|
-
const input = manifest.inputs[id === 'handler' ? manifest.handler : id]
|
|
347
|
-
const result = {
|
|
348
|
-
...input,
|
|
349
|
-
id,
|
|
350
|
-
assets: await input.assets(),
|
|
351
|
-
}
|
|
352
|
-
const code = inspect(result, { depth: 10 })
|
|
353
|
-
return new Response(code, { headers: { "Content-Type": "text/plain" } })
|
|
354
|
-
}),
|
|
355
|
-
)
|
|
356
|
-
.post(
|
|
357
|
-
"/_data/mutation/**:name",
|
|
358
|
-
eventHandler(async (event) => {
|
|
359
|
-
const id = "/" + getRouterParam(event, "name")
|
|
360
|
-
const body = await getWebRequest(event).json()
|
|
361
|
-
return await serverContext.fetchMutation({ name: id, body, headers: getRequestHeaders(event) })
|
|
362
|
-
}),
|
|
363
|
-
)
|
|
364
|
-
.post(
|
|
365
|
-
"/_data/submit-gf",
|
|
366
|
-
eventHandler(async (event) => {
|
|
367
|
-
const req = getWebRequest(event)
|
|
368
|
-
const headers = new Headers(req.headers)
|
|
369
|
-
headers.delete("content-length")
|
|
370
|
-
headers.delete("host")
|
|
371
|
-
headers.delete("connection")
|
|
372
|
-
headers.delete("pragma")
|
|
373
|
-
return await serverContext.fetchOrigin("/wp-json/ed/v1/gf/submit/", {
|
|
374
|
-
method: "POST",
|
|
375
|
-
headers: headers,
|
|
376
|
-
body: await req.blob(),
|
|
377
|
-
})
|
|
378
|
-
}),
|
|
379
|
-
)
|
|
380
|
-
|
|
381
|
-
const aiRouter = createRouter()
|
|
382
|
-
.get(
|
|
383
|
-
"/_ai/page",
|
|
384
|
-
eventHandler(async (event) => {
|
|
385
|
-
const id = "/"
|
|
386
|
-
const url = getRequestURL(event)
|
|
387
|
-
const page = await renderPageForIndexing({ pathname: id, newOrigin: url.origin, hostname: url.hostname })
|
|
388
|
-
return new Response(page.contents, {
|
|
389
|
-
headers: {
|
|
390
|
-
"Content-Type": "text/html; charset=utf-8",
|
|
391
|
-
"Cache-Control": "no-store",
|
|
392
|
-
},
|
|
393
|
-
})
|
|
394
|
-
}),
|
|
395
|
-
)
|
|
396
|
-
.get(
|
|
397
|
-
"/_ai/page/**:name",
|
|
398
|
-
eventHandler(async (event) => {
|
|
399
|
-
const id = "/" + getRouterParam(event, "name")
|
|
400
|
-
const url = getRequestURL(event)
|
|
401
|
-
|
|
402
|
-
const page = await renderPageForIndexing({ pathname: id, newOrigin: url.origin, hostname: url.hostname })
|
|
403
|
-
return new Response(page.contents, {
|
|
404
|
-
headers: {
|
|
405
|
-
"Content-Type": "text/html; charset=utf-8",
|
|
406
|
-
"Cache-Control": "no-store",
|
|
407
|
-
},
|
|
408
|
-
})
|
|
409
|
-
}),
|
|
410
|
-
)
|
|
411
|
-
|
|
412
|
-
export default eventHandler({
|
|
413
|
-
handler: async (event) => {
|
|
414
|
-
const serverContext = ServerContext.main
|
|
415
|
-
const url = getRequestURL(event)
|
|
416
|
-
|
|
417
|
-
// Vercel invokes ISR functions through an internal bracket route. Nitro normally
|
|
418
|
-
// restores the public pathname before this handler runs, but it is not guaranteed
|
|
419
|
-
// for every stale/revalidation request, so resolve it before any route checks.
|
|
420
|
-
const vercelRouteMatches = getRequestHeaders(event)["x-now-route-matches"]
|
|
421
|
-
const isrRoute = vercelRouteMatches
|
|
422
|
-
? new URLSearchParams(vercelRouteMatches).get("__isr_route")
|
|
423
|
-
: url.searchParams.get("__isr_route")
|
|
424
|
-
if (isrRoute) {
|
|
425
|
-
url.pathname = isrRoute
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
await Promise.allSettled([viewManifestReader.preloadAll(), blockManifestReader.preloadAll()])
|
|
429
|
-
|
|
430
|
-
// RPC
|
|
431
|
-
const isRPC = serverContext.rpcBases.some((base) => url.pathname.startsWith(base))
|
|
432
|
-
if (isRPC) {
|
|
433
|
-
return handleRPC(event)
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
// Data API
|
|
437
|
-
if (url.pathname.startsWith("/_data/")) {
|
|
438
|
-
return router.handler(event)
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
// LLM indexing route
|
|
442
|
-
if (url.pathname.startsWith("/_ai/")) {
|
|
443
|
-
return aiRouter.handler(event)
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
// Outdated build assets
|
|
447
|
-
if (url.pathname.match(/^\\/(_build|_admin)/)) {
|
|
448
|
-
return new Response("", { status: 404 })
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
// Proxy WordPress
|
|
452
|
-
if ((url.pathname.includes(".") && !url.pathname.includes("[")) || url.pathname.startsWith("/graphql") || url.pathname.startsWith("/wp-")) {
|
|
453
|
-
return proxyWpAdmin(event)
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
// Enforce trailing slashes
|
|
457
|
-
if (!url.pathname.endsWith("/")) {
|
|
458
|
-
url.pathname = withTrailingSlash(url.pathname)
|
|
459
|
-
return Response.redirect(url, 301)
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
${process.env.VERCEL_SKEW_PROTECTION_ENABLED &&
|
|
463
|
-
code /* tsx*/ `
|
|
464
|
-
// Skew protection
|
|
465
|
-
setCookie(event, "__vdpl", ${JSON.stringify(process.env.VERCEL_DEPLOYMENT_ID ?? "")}, {
|
|
466
|
-
httpOnly: false,
|
|
467
|
-
path: "/",
|
|
468
|
-
})
|
|
469
|
-
`}
|
|
470
|
-
|
|
471
|
-
// SSR
|
|
472
|
-
return renderPage({ pathname: url.pathname, newOrigin: url.origin, hostname: url.hostname, bypass: serverContext.shouldBypass(event) })
|
|
473
|
-
},
|
|
474
|
-
})
|
|
475
|
-
`,
|
|
476
|
-
});
|
|
477
|
-
}
|
|
478
|
-
if (opts.serverless) {
|
|
479
|
-
// codegen.registerFile({
|
|
480
|
-
// name: "handler.wp-proxy.ts",
|
|
481
|
-
// generate: code/* tsx */ `
|
|
482
|
-
// /// <reference types="vinxi/types/server" />
|
|
483
|
-
// import { proxyWpAdmin } from "eddev/server"
|
|
484
|
-
// import { eventHandler } from "vinxi/http"
|
|
485
|
-
// import "./context.js"
|
|
486
|
-
// export default eventHandler(async (event) => {
|
|
487
|
-
// return proxyWpAdmin(event)
|
|
488
|
-
// })
|
|
489
|
-
// `,
|
|
490
|
-
// })
|
|
491
|
-
}
|
|
492
|
-
codegen.registerFile({
|
|
493
|
-
name: "manifest/blocks.ts",
|
|
494
|
-
generate: async () => {
|
|
495
|
-
const blockManifest = await project.blocks.get();
|
|
496
|
-
let blockImports = [];
|
|
497
|
-
let blockEntries = [];
|
|
498
|
-
for (const [name, block] of Object.entries(blockManifest.blocks)) {
|
|
499
|
-
if (name.match(/^_[a-z]+$/i))
|
|
500
|
-
continue;
|
|
501
|
-
const importSource = JSON.stringify("../../../" + block.fileName);
|
|
502
|
-
const jsName = pascalCase(name);
|
|
503
|
-
if (block.dynamic) {
|
|
504
|
-
const importStatement = `dynamic(() => import(${importSource}), ${JSON.stringify(block.fileName)})`;
|
|
505
|
-
blockEntries.push(JSON.stringify(block.acfName) + ": " + importStatement);
|
|
506
|
-
}
|
|
507
|
-
else {
|
|
508
|
-
blockImports.push(`import ${jsName} from ${importSource}`);
|
|
509
|
-
blockEntries.push(JSON.stringify(block.acfName) + ": " + jsName);
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
return code /* ts */ `
|
|
513
|
-
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
514
|
-
import { blockManifestReader } from 'eddev/_internal'
|
|
515
|
-
import { dynamic } from 'eddev/dynamic'
|
|
516
|
-
import core from '../../../blocks/_core'
|
|
517
|
-
${blockImports.join("\n")}
|
|
518
|
-
|
|
519
|
-
const manifest = {
|
|
520
|
-
${blockEntries.join(",\n")},
|
|
521
|
-
...core
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
const info = {
|
|
525
|
-
${Object.entries(blockManifest.blocks)
|
|
526
|
-
.filter(([name]) => !name.match(/^_[a-z]+$/i))
|
|
527
|
-
.map(([name, block]) => {
|
|
528
|
-
return (JSON.stringify(block.acfName) +
|
|
529
|
-
": " +
|
|
530
|
-
JSON.stringify({
|
|
531
|
-
slug: block.slug,
|
|
532
|
-
tags: block.tags,
|
|
533
|
-
flags: block.flags ?? {},
|
|
534
|
-
}));
|
|
535
|
-
})
|
|
536
|
-
.join(",\n")}
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
blockManifestReader.set(manifest, info)
|
|
540
|
-
|
|
541
|
-
export default manifest
|
|
542
|
-
|
|
543
|
-
if (import.meta.hot) {
|
|
544
|
-
import.meta.hot.accept()
|
|
545
|
-
}
|
|
546
|
-
`;
|
|
547
|
-
},
|
|
548
|
-
subscribe: project.blocks.subscribe,
|
|
549
|
-
});
|
|
550
|
-
codegen.registerFile({
|
|
551
|
-
name: "manifest/admin.ts",
|
|
552
|
-
generate: async () => {
|
|
553
|
-
const fieldManifest = await project.fields.get();
|
|
554
|
-
const widgetManifest = await project.widgets.get();
|
|
555
|
-
const blockManifest = await project.blocks.get();
|
|
556
|
-
return code /* ts */ `
|
|
557
|
-
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
558
|
-
import { adminManifestReader } from 'eddev/_internal'
|
|
559
|
-
import editorConfig from '../../../blocks/_editor'
|
|
560
|
-
|
|
561
|
-
const fields = {${Object.entries(fieldManifest.fields)
|
|
562
|
-
.map(([name, field]) => {
|
|
563
|
-
const importStatement = `() => import(${JSON.stringify("../../../" + field.fileName)}).then(m => m.default)`;
|
|
564
|
-
return JSON.stringify(field.slug) + ": " + importStatement;
|
|
565
|
-
})
|
|
566
|
-
.join(",\n")}}
|
|
567
|
-
const widgets = {${Object.entries(widgetManifest.widgets)
|
|
568
|
-
.map(([name, widget]) => {
|
|
569
|
-
const importStatement = `() => import(${JSON.stringify("../../../" + widget.fileName)}).then(m => m.default)`;
|
|
570
|
-
return JSON.stringify(widget.slug) + ": " + importStatement;
|
|
571
|
-
})
|
|
572
|
-
.join(",\n")}}
|
|
573
|
-
|
|
574
|
-
const blockTemplateParts = {${Object.entries(blockManifest.templateParts)
|
|
575
|
-
.map(([name, part]) => {
|
|
576
|
-
return JSON.stringify(name) + ": " + JSON.stringify(part);
|
|
577
|
-
})
|
|
578
|
-
.join(",\n")}}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
const manifest = {
|
|
582
|
-
fields,
|
|
583
|
-
widgets,
|
|
584
|
-
editorConfig,
|
|
585
|
-
blockTemplateParts
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
adminManifestReader.set(manifest)
|
|
589
|
-
|
|
590
|
-
export default manifest
|
|
591
|
-
|
|
592
|
-
export { editorConfig }
|
|
593
|
-
|
|
594
|
-
if (import.meta.hot) {
|
|
595
|
-
import.meta.hot.accept()
|
|
596
|
-
}
|
|
597
|
-
`;
|
|
598
|
-
},
|
|
599
|
-
subscribe: (callback) => {
|
|
600
|
-
const unsub = [
|
|
601
|
-
project.fields.subscribe(callback),
|
|
602
|
-
project.widgets.subscribe(callback),
|
|
603
|
-
project.blocks.subscribe(callback),
|
|
604
|
-
];
|
|
605
|
-
return () => unsub.forEach((u) => u());
|
|
606
|
-
},
|
|
607
|
-
});
|
|
608
|
-
codegen.registerFile({
|
|
609
|
-
name: "manifest/views.ts",
|
|
610
|
-
generate: async () => {
|
|
611
|
-
const viewManifest = await project.views.get();
|
|
612
|
-
return code /* ts */ `
|
|
613
|
-
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
614
|
-
import { viewManifestReader } from 'eddev/_internal'
|
|
615
|
-
import { dynamic } from 'eddev/dynamic'
|
|
616
|
-
const manifest = {${Object.entries(viewManifest.views).map(([name, view]) => {
|
|
617
|
-
const src = "../../../" + view.fileName;
|
|
618
|
-
let importStatement;
|
|
619
|
-
if (name.startsWith("_")) {
|
|
620
|
-
importStatement = imp(name + "=" + src);
|
|
621
|
-
}
|
|
622
|
-
else {
|
|
623
|
-
importStatement = code `dynamic(() => import(${JSON.stringify(src)}), ${JSON.stringify(view.fileName)})`;
|
|
624
|
-
}
|
|
625
|
-
return code `${JSON.stringify(view.slug)}: ${importStatement},\n`;
|
|
626
|
-
})}}
|
|
627
|
-
|
|
628
|
-
viewManifestReader.set(manifest)
|
|
629
|
-
|
|
630
|
-
export default manifest
|
|
631
|
-
|
|
632
|
-
if (import.meta.hot) {
|
|
633
|
-
import.meta.hot.accept()
|
|
634
|
-
}
|
|
635
|
-
`;
|
|
636
|
-
},
|
|
637
|
-
subscribe: project.views.subscribe,
|
|
638
|
-
});
|
|
639
|
-
codegen.registerFile({
|
|
640
|
-
name: "manifest/styles.ts",
|
|
641
|
-
generate: async () => {
|
|
642
|
-
return code /* ts */ `
|
|
643
|
-
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
644
|
-
export const getCssText = undefined
|
|
645
|
-
export const editorGlobalStyles = () => {}
|
|
646
|
-
`;
|
|
647
|
-
},
|
|
648
|
-
});
|
|
649
|
-
codegen.registerFile({
|
|
650
|
-
name: "manifest/tailwind-config.ts",
|
|
651
|
-
generate: async () => {
|
|
652
|
-
return code /* ts */ `
|
|
653
|
-
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
654
|
-
import tw from "../../../tailwind.config.ts"
|
|
655
|
-
import resolveConfig from 'tailwindcss/resolveConfig'
|
|
656
|
-
import { devToolsStore } from 'eddev/devtools'
|
|
657
|
-
|
|
658
|
-
const value = resolveConfig(tw)
|
|
659
|
-
devToolsStore.tailwindConfig = value
|
|
660
|
-
|
|
661
|
-
if (import.meta.hot) {
|
|
662
|
-
import.meta.hot.accept()
|
|
663
|
-
}
|
|
664
|
-
`;
|
|
665
|
-
},
|
|
666
|
-
});
|
|
667
|
-
if (opts.serverless) {
|
|
668
|
-
codegen.registerFile({
|
|
669
|
-
name: "manifest/routes.ts",
|
|
670
|
-
generate: async () => {
|
|
671
|
-
const routeManifest = await project.serverRoutes.get();
|
|
672
|
-
return code /* ts */ `
|
|
673
|
-
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
674
|
-
import { instantiateRouter } from "eddev/server"
|
|
675
|
-
${routeManifest.contextFileName
|
|
676
|
-
? code /*ts*/ `
|
|
677
|
-
import createContext from "../../../${routeManifest.contextFileName}"
|
|
678
|
-
`
|
|
679
|
-
: code /*ts*/ `
|
|
680
|
-
const createContext = () => ({})
|
|
681
|
-
`}
|
|
682
|
-
|
|
683
|
-
const router = instantiateRouter({${Object.entries(routeManifest.routes).map(([name, route]) => {
|
|
684
|
-
const src = "../../../" + route.fileName;
|
|
685
|
-
const importStatement = imp(camelCase(name) + "=" + src);
|
|
686
|
-
return code `${JSON.stringify(route.prefix)}: ${importStatement},\n`;
|
|
687
|
-
})}})
|
|
688
|
-
|
|
689
|
-
export { createContext, router }
|
|
690
|
-
`;
|
|
691
|
-
},
|
|
692
|
-
subscribe: project.serverRoutes.subscribe,
|
|
693
|
-
});
|
|
694
|
-
codegen.registerFile({
|
|
695
|
-
name: "rpc.ts",
|
|
696
|
-
generate: code /* tsx */ `
|
|
697
|
-
/// <reference types="vinxi/types/server" />
|
|
698
|
-
/** IMPORTANT: This file is auto-generated by eddev. Do not edit. */
|
|
699
|
-
import "./context.js"
|
|
700
|
-
import { fetchRequestHandler } from "@trpc/server/adapters/fetch"
|
|
701
|
-
import { parseURL, stringifyParsedURL } from "ufo"
|
|
702
|
-
import { EventHandlerRequest, getWebRequest, H3Event, setResponseHeaders } from "vinxi/http"
|
|
703
|
-
import { createContext, router } from "./manifest/routes.ts"
|
|
704
|
-
import { ServerContext } from "eddev/server"
|
|
705
|
-
|
|
706
|
-
export function handleRPC(event: H3Event<EventHandlerRequest>) {
|
|
707
|
-
const serverContext = ServerContext.main
|
|
708
|
-
|
|
709
|
-
// Handle CORS
|
|
710
|
-
setResponseHeaders(event, serverContext.getCorsHeaders(event.headers.get("origin") ?? event.headers.get("referer") ?? ""))
|
|
711
|
-
if (event.method === "OPTIONS") {
|
|
712
|
-
event.node.res.statusCode = 204
|
|
713
|
-
event.node.res.statusMessage = "No Content."
|
|
714
|
-
return "OK"
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
// Update URLs with dots, which tRPC prefers
|
|
718
|
-
const originalReq = getWebRequest(event)
|
|
719
|
-
const parsed = parseURL(originalReq.url)
|
|
720
|
-
parsed.pathname = "/" + parsed.pathname.replace(/(^\\/|\\/$)/g, "").replace(/\\//g, ".")
|
|
721
|
-
const req = new Request(stringifyParsedURL(parsed), originalReq)
|
|
722
|
-
|
|
723
|
-
// Handle any early results which are Responses
|
|
724
|
-
function processEarlyResult(value: any): Response | undefined {
|
|
725
|
-
if (value instanceof Response) {
|
|
726
|
-
return value
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
return new Promise(async (resolve) => {
|
|
731
|
-
let sent = false
|
|
732
|
-
const defaultResponse = await fetchRequestHandler({
|
|
733
|
-
endpoint: "/",
|
|
734
|
-
req: req,
|
|
735
|
-
router: router,
|
|
736
|
-
createContext: async (opts) => {
|
|
737
|
-
return {
|
|
738
|
-
...(await createContext(opts)),
|
|
739
|
-
searchParams: opts.info.url?.searchParams,
|
|
740
|
-
server: serverContext,
|
|
741
|
-
}
|
|
742
|
-
},
|
|
743
|
-
onError: (err) => console.error(err),
|
|
744
|
-
batching: { enabled: false },
|
|
745
|
-
// If a Response object is returned by a route, it will be sent as the response
|
|
746
|
-
responseMeta(opts) {
|
|
747
|
-
const value = opts?.data?.[0]?.["result"]?.["data"]
|
|
748
|
-
const response = processEarlyResult(value)
|
|
749
|
-
if (response) {
|
|
750
|
-
sent = true
|
|
751
|
-
resolve(response)
|
|
752
|
-
}
|
|
753
|
-
return {}
|
|
754
|
-
},
|
|
755
|
-
})
|
|
756
|
-
if (sent) return
|
|
757
|
-
resolve(defaultResponse)
|
|
758
|
-
})
|
|
759
|
-
}
|
|
760
|
-
`,
|
|
761
|
-
});
|
|
762
|
-
}
|
|
763
|
-
return codegen;
|
|
764
|
-
}
|