@joystick.js/node-canary 0.0.0-canary.366 → 0.0.0-canary.368
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/middleware/render/index.js +1 -1
- package/dist/app/middleware/session.js +1 -1
- package/dist/app/ssr/set_head_tags_in_html.js +1 -1
- package/package.json +1 -1
- package/src/app/middleware/render/index.js +1 -1
- package/src/app/middleware/session.js +0 -2
- package/src/app/ssr/set_head_tags_in_html.js +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
import w from"fs";import p from"../../../lib/dynamic_import.js";import c from"../generate_joystick_error_page.js";import k from"../../../lib/get_joystick_build_path.js";import j from"../../../lib/get_translations.js";import x from"./get_url.js";import _ from"../../../lib/path_exists.js";import v from"../../ssr/index.js";import
|
|
1
|
+
import w from"fs";import p from"../../../lib/dynamic_import.js";import c from"../generate_joystick_error_page.js";import k from"../../../lib/get_joystick_build_path.js";import j from"../../../lib/get_translations.js";import x from"./get_url.js";import _ from"../../../lib/path_exists.js";import v from"../../ssr/index.js";import"../../../lib/get_browser_safe_request.js";const{readFile:z}=w.promises,i=k(),A=()=>z("index.html","utf-8"),D=(s,e,f,d={})=>{e.render=async(n="",t={})=>{const u=n?.substring(0,1)==="/"?n?.replace("/",""):n,r=t?.layout?.substring(0,1)==="/"?t?.layout?.replace("/",""):t?.layout,a=`${i}${u}`,o=t?.layout?`${i}${r}`:null;if(!await _(a))return e.status(404).send(c({type:"page_not_found",path:`res.render('${a}')`,frame:null,stack:`A page component at the path ${a} could not be found.`}));if(o&&!await _(o))return e.status(404).send(c({type:"layout_not_found",path:`res.render('${a}', { layout: '${r}' })`,frame:null,stack:`A layout component at the path ${t?.layout} could not be found.`}));const l=await p(`${a}?v=${new Date().getTime()}`),h=o?await p(`${o}?v=${new Date().getTime()}`):null,m={...t?.props||{}};o&&(m.page=l);const y=await A(),g=await j({joystick_build_path:i,render_component_path:n,req:s}),$=x(s),b=await v({api_schema:d?.options?.api,attributes:t?.attributes,base_html:y,component_options:{props:m,translations:g,url:$},component_to_render:h||l,head:t?.head,render_component_path:u,render_layout_path:r,req:s});return e.status(200).send(b)},f()};var K=D;export{K as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import i from"../databases/queries/sessions.js";import n from"../../lib/set_cookie.js";const c=async(
|
|
1
|
+
import i from"../databases/queries/sessions.js";import n from"../../lib/set_cookie.js";const c=async(o,e,t)=>{let s=o?.cookies?.joystick_session;(s?await i("get_session",{session_id:s}):null)||(s=await i("create_session"),n(e,"joystick_session",s)),o.cookies={...o?.cookies||{},joystick_session:s},o.context={...o?.context||{},session:await i("get_session",{session_id:s})},t()};var l=c;export{l as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import c from"node-html-parser";import _ from"../../lib/types.js";const f=(u="",t=null,
|
|
1
|
+
import c from"node-html-parser";import _ from"../../lib/types.js";const f=(u="",t=null,p={})=>{const g=c.parse(u),i=g.querySelector("head");if(p?.context?.session){const s=c.parse("<meta />").querySelector("meta");s.setAttribute("name","csrf"),s.setAttribute("content",p?.context?.session?.csrf),i.appendChild(s)}if(!t)return g.toString();if(t.title){const e=i.querySelector("title");if(e){const s=c.parse(`<title>${t.title}</title>`);i.exchangeChild(e,s)}e||i.insertAdjacentHTML("afterbegin",`<title>${t.title}</title>`)}if(t.tags&&t.tags.meta&&_.is_array(t.tags.meta)&&t.tags.meta.length>0)for(let e=0;e<t?.tags?.meta?.length;e+=1){const s=t.tags.meta[e],r=i.querySelector(`meta[name="${s.name}"]`),a=c.parse("<meta />"),n=Object.entries(s||{});for(let l=0;l<n?.length;l+=1){const[o,m]=n[l];a.querySelector("meta").setAttribute(o,m)}r&&i.exchangeChild(r,a),r||i.appendChild(a)}if(t.tags&&t.tags.link&&_.is_array(t.tags.link)&&t.tags.link.length>0)for(let e=0;e<t?.tags?.link?.length;e+=1){const s=t?.tags?.link[e],r=c.parse("<link />"),a=Object.entries(s||{});for(let n=0;n<a?.length;n+=1){const[l,o]=a[n];r.querySelector("link").setAttribute(l,o)}i.appendChild(r)}if(t.tags&&t.tags.script&&Array.isArray(t.tags.script)&&t.tags.script.length>0)for(let e=0;e<t?.tags?.script?.length;e+=1){const s=t.tags.script[e],r=c.parse("<script></script>"),a=Object.entries(s||{});for(let n=0;n<a?.length;n+=1){const[l,o]=a[n];r.querySelector("script").setAttribute(l,o)}i.appendChild(r)}if(t.jsonld){const e=c.parse("<script></script>"),s=e.querySelector("script");s.setAttribute("type","application/ld+json"),s.set_content(JSON.stringify(t.jsonld,null,2)),i.appendChild(e)}return g.toString()};var S=f;export{S as default};
|
package/package.json
CHANGED
|
@@ -81,7 +81,7 @@ const render_middleware = (req, res, next, app_instance = {}) => {
|
|
|
81
81
|
head: render_options?.head,
|
|
82
82
|
render_component_path: sanitized_render_component_path,
|
|
83
83
|
render_layout_path: sanitized_render_layout_path,
|
|
84
|
-
req
|
|
84
|
+
req,
|
|
85
85
|
});
|
|
86
86
|
|
|
87
87
|
return res.status(200).send(html);
|
|
@@ -5,8 +5,6 @@ const set_head_tags_in_html = (html_string = '', head = null, req = {}) => {
|
|
|
5
5
|
const html = html_parser.parse(html_string);
|
|
6
6
|
const head_tag = html.querySelector('head');
|
|
7
7
|
|
|
8
|
-
console.log(req?.context);
|
|
9
|
-
|
|
10
8
|
if (req?.context?.session) {
|
|
11
9
|
const meta_tag_wrapper = html_parser.parse(`<meta />`);
|
|
12
10
|
const tag = meta_tag_wrapper.querySelector('meta');
|