create-ampless 1.0.0-alpha.143 → 1.0.0-alpha.146
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.
|
@@ -1,68 +1,4 @@
|
|
|
1
|
-
import type { Post } from 'ampless'
|
|
2
1
|
import { admin } from '@/lib/admin'
|
|
2
|
+
import { createPreviewRouteHandler } from '@ampless/admin/api'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
* Preview-only Route Handler. Client-side `<PostForm>` / `<PostHistoryPanel>`
|
|
6
|
-
* POST a draft Post to this endpoint while the preview tab is open; we
|
|
7
|
-
* render the body + page-level scripts via `ampless.renderBody` /
|
|
8
|
-
* `publicPostScriptsForPage` and return a fully-rendered HTML string
|
|
9
|
-
* that the admin shows in an iframe (`sandbox="allow-scripts allow-same-origin"`,
|
|
10
|
-
* v1 trust boundary expansion — admin preview content / plugin script are
|
|
11
|
-
* explicitly treated as trusted; see the iframe comment in post-form.tsx).
|
|
12
|
-
*
|
|
13
|
-
* Why a Route Handler instead of a Server Action: Next.js 15+
|
|
14
|
-
* refuses to compile Client Components that reach `react-dom/server`
|
|
15
|
-
* through a `'use server'` module, because the build traces the
|
|
16
|
-
* import graph from Client Components through Server Action modules.
|
|
17
|
-
* Putting this rendering behind a Route Handler decouples it from
|
|
18
|
-
* that graph entirely — the form fetches a plain HTTP endpoint and
|
|
19
|
-
* the bundler never walks from `<PostForm>` into here. The endpoint
|
|
20
|
-
* also gets an explicit `admin.isEditor()` gate so a future change
|
|
21
|
-
* to the `(admin)` route-group middleware can't silently turn
|
|
22
|
-
* preview into a content-leak vector for unpublished drafts.
|
|
23
|
-
*
|
|
24
|
-
* The `react-dom/server` import itself is loaded via dynamic
|
|
25
|
-
* `import()` inside the handler. Next.js 16's Turbopack flags any
|
|
26
|
-
* top-level static `import 'react-dom/server'` reached from the app
|
|
27
|
-
* router build (Route Handlers included), so we deliberately defer
|
|
28
|
-
* the resolution to request time — the module is still pulled from
|
|
29
|
-
* the same Node.js subpath that `next start` ships, just not visible
|
|
30
|
-
* to the build-time import-graph walker.
|
|
31
|
-
*
|
|
32
|
-
* Auth: locked to authenticated editors. Anonymous + reader access is
|
|
33
|
-
* 403. This matches the rest of `/admin/**`, which is gated by the
|
|
34
|
-
* `(admin)` route group + middleware, but we add an explicit check
|
|
35
|
-
* here as defence-in-depth against the middleware gate being
|
|
36
|
-
* misconfigured.
|
|
37
|
-
*/
|
|
38
|
-
export async function POST(req: Request): Promise<Response> {
|
|
39
|
-
const session = await admin.getServerSession()
|
|
40
|
-
if (!admin.isEditor(session)) {
|
|
41
|
-
return new Response('Forbidden', { status: 403 })
|
|
42
|
-
}
|
|
43
|
-
let draft: Post
|
|
44
|
-
try {
|
|
45
|
-
draft = (await req.json()) as Post
|
|
46
|
-
} catch {
|
|
47
|
-
return new Response('Bad Request', { status: 400 })
|
|
48
|
-
}
|
|
49
|
-
const ampless = await admin.getAmpless()
|
|
50
|
-
// IMPORTANT: include BOTH the body and the page-level scripts so
|
|
51
|
-
// widgets like x.com's `widgets.js` get a chance to hydrate in the
|
|
52
|
-
// iframe.
|
|
53
|
-
const node = (
|
|
54
|
-
<>
|
|
55
|
-
{await ampless.renderBody(draft)}
|
|
56
|
-
{await ampless.publicPostScriptsForPage([draft])}
|
|
57
|
-
</>
|
|
58
|
-
)
|
|
59
|
-
// Dynamic import: see top-of-file comment. The module is server-only
|
|
60
|
-
// and resolved at request time.
|
|
61
|
-
const { renderToStaticMarkup } = await import('react-dom/server')
|
|
62
|
-
return new Response(renderToStaticMarkup(node), {
|
|
63
|
-
headers: {
|
|
64
|
-
'Content-Type': 'text/html; charset=utf-8',
|
|
65
|
-
'Cache-Control': 'no-store',
|
|
66
|
-
},
|
|
67
|
-
})
|
|
68
|
-
}
|
|
4
|
+
export const POST = createPreviewRouteHandler(admin)
|
|
@@ -26,21 +26,21 @@
|
|
|
26
26
|
"@tiptap/pm": "^3.23.6",
|
|
27
27
|
"@tiptap/react": "^3.23.6",
|
|
28
28
|
"@tiptap/starter-kit": "^3.23.6",
|
|
29
|
-
"@ampless/plugin-analytics-ga4": "^0.2.0-alpha.
|
|
30
|
-
"@ampless/plugin-cookie-consent": "^0.1.0-alpha.
|
|
31
|
-
"@ampless/plugin-gtm": "^0.2.0-alpha.
|
|
32
|
-
"@ampless/plugin-og-image": "^0.2.0-alpha.
|
|
33
|
-
"@ampless/plugin-plausible": "^0.2.0-alpha.
|
|
34
|
-
"@ampless/plugin-reading-time": "^0.1.0-alpha.
|
|
35
|
-
"@ampless/plugin-rss": "^0.2.0-alpha.
|
|
36
|
-
"@ampless/plugin-schema-jsonld": "^0.1.1-alpha.
|
|
37
|
-
"@ampless/plugin-seo": "^0.2.0-alpha.
|
|
38
|
-
"@ampless/plugin-webhook": "^0.2.0-alpha.
|
|
39
|
-
"@ampless/admin": "^1.0.0-alpha.
|
|
40
|
-
"@ampless/backend": "^1.0.0-alpha.
|
|
41
|
-
"@ampless/runtime": "^1.0.0-alpha.
|
|
29
|
+
"@ampless/plugin-analytics-ga4": "^0.2.0-alpha.34",
|
|
30
|
+
"@ampless/plugin-cookie-consent": "^0.1.0-alpha.25",
|
|
31
|
+
"@ampless/plugin-gtm": "^0.2.0-alpha.33",
|
|
32
|
+
"@ampless/plugin-og-image": "^0.2.0-alpha.50",
|
|
33
|
+
"@ampless/plugin-plausible": "^0.2.0-alpha.33",
|
|
34
|
+
"@ampless/plugin-reading-time": "^0.1.0-alpha.23",
|
|
35
|
+
"@ampless/plugin-rss": "^0.2.0-alpha.50",
|
|
36
|
+
"@ampless/plugin-schema-jsonld": "^0.1.1-alpha.29",
|
|
37
|
+
"@ampless/plugin-seo": "^0.2.0-alpha.50",
|
|
38
|
+
"@ampless/plugin-webhook": "^0.2.0-alpha.51",
|
|
39
|
+
"@ampless/admin": "^1.0.0-alpha.85",
|
|
40
|
+
"@ampless/backend": "^1.0.0-alpha.72",
|
|
41
|
+
"@ampless/runtime": "^1.0.0-alpha.59",
|
|
42
42
|
"@digital-go-jp/tailwind-theme-plugin": "^0.3.4",
|
|
43
|
-
"ampless": "^1.0.0-alpha.
|
|
43
|
+
"ampless": "^1.0.0-alpha.50",
|
|
44
44
|
"aws-amplify": "^6.17.0",
|
|
45
45
|
"class-variance-authority": "^0.7.1",
|
|
46
46
|
"clsx": "^2.1.1",
|