UNPKG

@bolttech/server-side-next

Version:

This library was generated with [Nx](https://nx.dev).

3 lines (2 loc) 2.66 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_tslib-0e64cda4.js"),t=require("react/jsx-runtime"),n=require("react"),o=require("next/router"),s=require("axios"),r=require("next/head"),l=require("next/document"),i=require("styled-components"),a=require("@bolttech/essentials/src/components");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var d=c(s),u=c(r),p=c(l);class v extends p.default{static getInitialProps(n){var o,s,r,l,a,c;return e.__awaiter(this,void 0,void 0,(function*(){const e=new i.ServerStyleSheet,d=n.renderPage;try{n.renderPage=()=>d({enhanceApp:n=>o=>e.collectStyles(t.jsx(n,Object.assign({},o))),enhanceComponent:n=>o=>e.collectStyles(t.jsx(n,Object.assign({},o)))});const i=yield p.default.getInitialProps(n);return v.locale=null===(r=null===(s=null===(o=i.head)||void 0===o?void 0:o.find((e=>{var t;return"locale"===(null===(t=null==e?void 0:e.props)||void 0===t?void 0:t.name)})))||void 0===s?void 0:s.props)||void 0===r?void 0:r.content,v.font=null===(c=null===(a=null===(l=i.head)||void 0===l?void 0:l.find((e=>{var t;return"font"===(null===(t=null==e?void 0:e.props)||void 0===t?void 0:t.name)})))||void 0===a?void 0:a.props)||void 0===c?void 0:c.content,Object.assign(Object.assign({},i),{styles:t.jsxs(t.Fragment,{children:[i.styles,e.getStyleElement()]})})}finally{e.seal()}}))}render(){return t.jsxs(l.Html,Object.assign({lang:v.locale},{children:[t.jsx(l.Head,{children:v.font&&t.jsx(a.Fonts,{font:v.font})||null}),t.jsxs("body",{children:[t.jsx(l.Main,{}),t.jsx(l.NextScript,{})]})]}))}}var f=Object.freeze({__proto__:null,default:v});exports.Document=f,exports.Header=({pageProps:e})=>{const n=e,{locale:o,flow:s,partner:r,fonts:l}=n.config||{},i=(null==l?void 0:l.find((e=>e.flow===r||e.flow===s||"Direct"===e.flow)))||{};return t.jsxs(u.default,{children:[t.jsx("meta",{name:"locale",content:o}),t.jsx("meta",{name:"font",content:i[o]})]})},exports.WithSession=(s,r,l)=>n.memo((function(i){const a=r(),{locale:c,vertical:u}=l(),{query:p}=o.useRouter(),{cookie:v,setSessionStore:f}=a;return n.useEffect((()=>{"undefined"==typeof window||void 0!==v||p.slug&&p.slug.length>0&&!p.slug.includes("desktop")&&!p.slug.includes("mobile")||(()=>{e.__awaiter(this,void 0,void 0,(function*(){const e=yield d.default.post("/api/session/upsert",{locale:c,vertical:u,query:p}),{status:t,result:n}=e.data;t&&f(Object.assign(Object.assign({},n),{isReady:!0}))}))})()}),[]),t.jsx(s,Object.assign({},i,{session:a}))})),exports.reportWebVitals=function(e){"production"!==process.env.NODE_ENV&&process.env.LOG_WEBVITRAL_METRICS&&console.log(e)}; //# sourceMappingURL=sharedNext.js.map