Spartacus state transfer implementation - server-side-rendering

I installed SSR to Spartacus application with schematics command and run the application in SSR mode.
In my Chrome dev tools, I can see that content of my homepage was successfully generated by the SSR server.
However, I can see in my network tab, that the XHR requests are still sent and data is fetched with http calls instead of using data fetched by express.
I tried to use config from https://sap.github.io/spartacus-docs/ssr-transfer-state/#page-title in my app.module.ts providers with provideConfig (I also tried it with Config.Module.withConfig in app.module.ts imports as well) file but it didn't work, as CMS and products requests were still sent from client.
At the end of my rendered HTML I can see that state data is linked in key value format to script tag:
<script id="spartacus-state" type="application/json">...</script>
I am wondering if it is possible to use that data from HTML template on the client side and dont't fetch them again with HTTP calls (implementing Angular Universal transfer state in Spartacus app)
I would be very grateful for any advice regarding correct approach (overiding adapters or resolvers or any other solution) for the state transfer implementation in the Spartacus app.
Thank you.

The configured transfer state should work OOTB for some parts of the data, but not for everything. See the source code of cms-store.module.ts, product-store.module.ts and site-context-store.module.ts.
Note that by default the CMS page data is re-loaded in the client, unless you configure RouteLoadStrategy to ONCE in the routing config.
If you find that the Spartacus transfer state is not working correctly, please create a bug ticket in the Spartacus repo and reference it here.

Related

How to Keep a puppeteer instance in NextJS server

I'm using puppeteer in a NextJS server module and Only one instance of the puppeteer Browser (also with login information and some states from some puppeteer pages) is needed. I use globle.myBrowser to keep this instance.(because I don't need a database, so I can't store it in a database), if I don't keep it with globle.myBrowser, NextJs will load this module more than once, so I can't keep the state.
It's all good until when I modify this module, hot reload will not work, because global.myBrowser will still point to the old module and new module will not working.
My questions are:
Is there any other better way to keep this instance of puppeteer?
if using globle to track the instance, How can I detect hot reload? I using module.hot.accept but get: "accept is undefined.

Command / CLI based REST Http client to process bulk requests (i.e. like .http files)

Need a tool/setup in place that will trigger RESTful webAPI requests using a preformatted file (which contains Http request config and payload) .. like the .http file format supported by VScode REST client.
We need a CLI because the process is automated and runs in background. A typical scenario will be a .http file arriving in a folder. The tool will pick it up (usually there will be a single Http Request) and trigger that Http request. The response will be output to another file (not mandatory but a logging feature would be helpful in debugging).
Here're a few options we've been exploring -
Postman Newman
CURL with a windows Batch file (or use HttPie instead of curl)
Similar tools we've been exploring - VScode REST client, httpYAC, .. (not sure if such tools can be automated)
A console app based solution - using Node.js, C#, Python, php, ... it'll be highly customizable but this will be like start from scratch. So this is the last option if all the above fails.
We just need this piece to complete our data flow. And we're yet to face things like request throttle, delay, auth, ... but all of this needs to be preconfigured and automated. The setup can very based on the Http service provider we use (i.e. Shopify, Amazon, ...).
EDITT #1 :
Option#5. Forgot to mention that we had implemented a webAPI access demo using SQL SPs (OLE Automation) and we could achieve a lot of what we wanted. Here's a similar Ref.

Nextjs in Production

I know that Next.js can do SSR.
I have questions about production.
In my experience(no SSR). Frontend build static files, and then give the folder to backend to integrate.And there is only one server.
I want to know that if we want to use SSR with Next.js (not static site).
Do we need host two server? One for host backend(nodes, java…), another for host frontned(next.js)?
If I use nodejs as backend language.Can I write all api in next.js?(I mean frontend and backend code all use next.js, so that there is only one server).
If question one's answer is yes, I see the document use next start to host server, is it strong enough to host many users?
Do we need host two server? One for host backend(nodes, java…), another for host > frontned(next.js)?
In most cases you would have a single server producing the SSR as well as rendering the markup required for the client. The associated Javascript files that only the browser can be sent via a asset serving server ( e.g: An S3 bucket ) - You would front the whole thing using a CDN so your server would not get all public requests
If I use nodejs as backend language.Can I write all api in next.js?(I mean frontend and backend code all use next.js, so that there is only one server).
Yes, for simplistic uses you can checkout the api solve that NextJS ships with. https://nextjs.org/docs/api-routes/introduction
If question one's answer is yes, I see the document use next start to host ? server, is it strong enough to host many users?
You would use a next build and next start - With the latest optimizations nextjs adds Static site generation (SSG) - Sorry one more confusing term but this lets your backend nodejs app receive much lesser requests and be smart about serving repetitive requests, However even with these abilities you should front the whole thing using a CDN to ensure high availability and low operating costs.

Does nginx-rtmp provide interface to get current live stream info

As we know,nginx-rtmp provides stat function, but the result style is web page. I have several nginx server, I want to collect all the live streams info in these nginx server, and integrate them into my web system.So does nginx provide interface to get these info or is there any other idea to do it?
THANKS!
It also provides a stat.xml based on which the xsl builds the html. You can programatically parse the xml structure and build a list of the currently running streams on your server.

Using JMeter with iframes

I have a test plan for our UAT environment using JMeter and part of the user journey involves hitting a page with an iframe to accept payment using a payment provider.
The payment provider from the iframe has three stages:
Select payment type (VISA, MasterCard etc.)
Enter payment details (Card number, expiry etc.)
Enter status code (Approved or Declined because it is a test environment)
How do I implement these iframe requests using JMeter?
You can try and record it first. Use either JMeter proxy: http://jmeter.apache.org/usermanual/component_reference.html#HTTP(S)_Test_Script_Recorder
Or BlazeMeter's Chrome extension: http://community.blazemeter.com/knowledgebase/articles/231479-chrome-extension
You will then need to clean an parametrize your script. Take a look at CSV data set config: http://jmeter.apache.org/usermanual/component_reference.html#CSV_Data_Set_Config
If you need some video tutorials to do just that, take a look here: http://blazemeter.com/blog/jmeter-tutorial-video-series
You're best bet is probably BlazeMeter's JMeter chrome extension, though you need to change one of the settings.
When you are browsing a site that uses iframes, AJAX calls, JS based requests (etc) you need to into the "Advanced Options" in the extension and uncheck "Record Only Top Level Requests".
The extension will now record EVERY request your browser is making, so be sure to close any other tabs you have open.
The Test Script Recorder might be failing due to security issues on the domain in the iframe. The advantage of using the chrome extension is that it doesn't care if the requests are secure or not.

Resources