server-side-rendering

AWS Lambda @ng-toolkit failing for TypeError: express is not a function in angular 9 app

柔情痞子 提交于 2021-02-20 04:58:56
问题 I started deploying my demo Angular 9 application on AWS lambda and provide SSR. In order to achieve this, I used @ng-toolkit/universal and @ng-toolkit/serverless. Deployment happened successfully but demo application is not opening. Upon investigating AWS lambda logs, I found the following exception. Here is the package.json, where I have added express js in dependencies. { "name": "my-appg", "version": "0.0.0", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "test": "ng

Angular Lazy Load External JS files with Angular Universal

回眸只為那壹抹淺笑 提交于 2021-02-20 04:25:14
问题 https://maps.googleapis.com/maps/api/js?libraries=places&key=XXX This is inside index.html file, but i want to lazy load this script, because that module is lazy loaded and it's really not necessary for all users. I can't use trick with directly accessing the DOM and appending script el. because I want to use Angular Universal ( SSR ). 回答1: You can access the DOM even if you are using SSR. Add this to your lazy loaded module module or one of the components of your lazy loaded module import

Using Fragment to insert HTML rendered on the back end via dangerouslySetInnerHTML

拈花ヽ惹草 提交于 2021-02-18 06:34:24
问题 I used to compile and insert JSX components via <div key={ ID } dangerouslySetInnerHTML={ { __html: HTML } } /> which wrapped my HTML into a <div> : <div>my html from the HTML object</div> Now react > 16.2.0 has support for Fragments and I wonder if I can use that somehow to avoid wrapping my HTML in a <div> each time I get data from the back end. Running <Fragment key={ ID } dangerouslySetInnerHTML={ { __html: HTML } } /> will throw a warning Warning: Invalid prop `dangerouslySetInnerHTML`

Using Fragment to insert HTML rendered on the back end via dangerouslySetInnerHTML

筅森魡賤 提交于 2021-02-18 06:33:15
问题 I used to compile and insert JSX components via <div key={ ID } dangerouslySetInnerHTML={ { __html: HTML } } /> which wrapped my HTML into a <div> : <div>my html from the HTML object</div> Now react > 16.2.0 has support for Fragments and I wonder if I can use that somehow to avoid wrapping my HTML in a <div> each time I get data from the back end. Running <Fragment key={ ID } dangerouslySetInnerHTML={ { __html: HTML } } /> will throw a warning Warning: Invalid prop `dangerouslySetInnerHTML`

Angular Universal set set-cookies in request header

℡╲_俬逩灬. 提交于 2021-02-11 14:22:33
问题 I have anngular Universal SSR application with authentication. I save auth token inside http cookies(set-cookies). Now when I refresh application I see unauthenticated page at first, and after a second it converts to authenticated state. I understand that this happens because Universals renderer server doesn't pass token from cookies to API when rendering page. So how can I force Universal server to render page in authenticated state? 回答1: Angular universal does not transfer cookies when

ReferenceError: window is not defined Angular Universal

自古美人都是妖i 提交于 2021-02-10 14:14:38
问题 I'm using Angular 10 and trying to implement SSR in my project. When I run the npm run serve:ssr I'm getting the below error ReferenceError: window is not defined When I googled, they suggested to add domino So below is my server.ts .... const scripts = fs.readFileSync('dist/asfc-web/browser/index.html').toString(); const window = domino.createWindow(scripts); global['window'] = window; global['document'] = window.document; .... still getting the same error, Please guide me how to resolve

ReferenceError: window is not defined Angular Universal

扶醉桌前 提交于 2021-02-10 14:14:35
问题 I'm using Angular 10 and trying to implement SSR in my project. When I run the npm run serve:ssr I'm getting the below error ReferenceError: window is not defined When I googled, they suggested to add domino So below is my server.ts .... const scripts = fs.readFileSync('dist/asfc-web/browser/index.html').toString(); const window = domino.createWindow(scripts); global['window'] = window; global['document'] = window.document; .... still getting the same error, Please guide me how to resolve

ReferenceError: window is not defined Angular Universal

浪子不回头ぞ 提交于 2021-02-10 14:11:03
问题 I'm using Angular 10 and trying to implement SSR in my project. When I run the npm run serve:ssr I'm getting the below error ReferenceError: window is not defined When I googled, they suggested to add domino So below is my server.ts .... const scripts = fs.readFileSync('dist/asfc-web/browser/index.html').toString(); const window = domino.createWindow(scripts); global['window'] = window; global['document'] = window.document; .... still getting the same error, Please guide me how to resolve

How to hide data from network tab?

家住魔仙堡 提交于 2021-02-10 07:20:07
问题 In my angular application if I go to dev tools network tab I will be able to see the response and request coming from the back end. Do anyone know how to hide or mask this data, is this possible if I do the server-side rendering? 回答1: Requests will be shown. This cannot be stopped, the application is making requests and this will be logged to the network tab by the browser, as mentioned in the comments, if there are security concenrns you should be handling this a different way. Do not send

Internal API fetch with getServerSideProps? (Next.js)

主宰稳场 提交于 2021-02-08 09:08:03
问题 I'm new to Next.js and I'm trying to understand the suggested structure and dealing with data between pages or components. For instance inside my home.js page, I fetch a internal API called /api/user.js where it sends back to me some user data from mongodb. The fetch right now happens inside the getServerSideProps() which passes various props to the page after some math. From my understanding this is the way to go for a good SEO, since props get fetched/modified server side and the page gets