@carats/ssr 0.0.1 → 0.0.2
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/index.d.ts +13 -0
- package/dist/index.js +2 -0
- package/package.json +2 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CaratsRequest, Hallmark } from '@carats/core';
|
|
2
|
+
import { Facets } from '@carats/render';
|
|
3
|
+
|
|
4
|
+
interface CaratsServerEntry {
|
|
5
|
+
getApiData: <T = any>(req: CaratsRequest) => Promise<T>;
|
|
6
|
+
render: (req: CaratsRequest) => Promise<{
|
|
7
|
+
html?: string;
|
|
8
|
+
head?: string;
|
|
9
|
+
}>;
|
|
10
|
+
}
|
|
11
|
+
declare function defineServerEntry(facets: Facets, hallmarks: Record<string, Hallmark>): CaratsServerEntry;
|
|
12
|
+
|
|
13
|
+
export { type CaratsServerEntry, defineServerEntry as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{getPageComponent as d,renderPage as f}from"@carats/render";import{matchRoute as h,parseUrl as c,qs as g,replaceParams as P}from"@carats/url";import{init as y,transpile as C}from"jjsx";function R(o,p){y();async function u(r){let{path:n}=c(r.url);for(let[i,t]of Object.entries(p)){let a=h(i,n);if(a)return await t({params:a,url:r.url,cookies:r.cookies,headers:r.headers,method:r.method,data:r.data})}return{_status:404,error:"API endpoint not found"}}async function m(r){let{suspense:{error:n}}=o,{query:i}=c(r.url),{component:t,params:a}=d.call(o,r.url),e=t.defaultProps||{url:r.url,params:a},s="";if(t.ssp){let l=P(t.ssp+g(i),a);e=await u(r),s=e.head||"",s+=`
|
|
2
|
+
<script>window.ssp=${JSON.stringify({for:l,data:e})}</script>`}try{return{html:await f.call(o,t,e),head:s}}catch(l){return{html:C(n(l)),head:s}}}return{getApiData:u,render:m}}export{R as default};
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carats/ssr",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "SSG module for Carats",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"files": ["dist"],
|
|
8
8
|
"type": "module",
|
|
9
9
|
"scripts": {
|
|
10
|
+
"prepublishOnly": "npm run build",
|
|
10
11
|
"build": "tsup ./src/index.ts --config ../../tsup.config.ts"
|
|
11
12
|
},
|
|
12
13
|
"publishConfig": {
|