route to statically generated page based on url with NextJS - reactjs

I'm building an app where different users can register and get a frontpage. I then assign each user a subdomain (say userA.mydomain.com) and would like to display the user's frontpage when we access his subdomain.
I already got it working that the different subdomains route to the NextJS app, but now I need to display the user's data on that frontpage. So when we go to userA.mydomain.com I need to display userA's data.
I know that I can generate the static pages for each user by creating a page under /pages/frontpages/[userId].tsx, but then the domain would look like this: userA.mydomain.com/frontpages/userA. This is redundant, because we already know the userId because of the subdomain. Also we can access other user's frontpages from another user's subdomain.
I also know that I can fetch the data inside the index page, but then we loose all benefits of statically generated pages.
My questions are:
Is there a way to get what we would have with pages/[userId].tsx but for the index page? I don't want to fetch the data inside the index page itself because then I loose the benefit of statically generated pages. Maybe there's something that we can do with getStaticPaths?
For example is it possible to prerender the frontpages using getStaticPaths for pages/frontpages/[userId].tsx and then inside the index page we just render the content of the generated frontpage page (based on the subdomain of the url)?

Related

referrer in segment.io analytics.page() in a SPA

I am trying to integrate segment.io to work with Angular. My angular app is a SPA so I have to add some code to my components to allow segment to register the page visits.
In the code used to register page visits, there is a property called referrer that, according to the docs is:
Full URL of the previous page. Equivalent to document.referrer from
the DOM API.
The problem I am having is the referrer property value sometimes just remains empty, or sticks to one page even if I move to several other different pages.
So my questions are:
Does referrer mean links outside my app or also the previous routes visited within my app?
Am I supposed to set this manually in the app?
Yes, you're supposed to set it manually in your existing pageview hits to Segment.
Basically, in your case, referrer would be just the previous route. If the previous route doesn't exist, then use the document.referrer.
And yes, organically, if your app doesn't have a previous route, then document.referrer may contain an outside url, which is completely fine and expected.
Also, Segment provides pretty neat support for questions like this, so you can confirm with them.

How can I set in code page ID to be detect in google analytics?

I need to give any page in my website a unique ID to be detected in google analytics or firebase analytics.
I will explain:
First of all, I'm developing using React.js.
I have lots of pages (routes) on my website. for example:
https://mywebsite.com/website1
https://mywebsite.com/website2
https://mywebsite.com/website3
In someday, I will change the route of the page and I want to keep detect the analytics data from the history using API.
Because of that, I need to set a constant ID for each page to be detected no matter what the route is.
You can do it by creating a datalayer variable - if you kept the datalayer the same on the page (even if the URL is different) you can send the variable as a custom dimension to Google Analytics. You can then report on that custom dimension as if it was a page.

How to pass query string from Shopify to an embedded app?

I'm building a Shopify app with Next.js and I need to grab the query string so I can check in getServerSideProps the identity of the merchant (bear in mind that Cookies are not recommended for Shopify apps)
When visiting some apps I noticed some of them are getting the query string passed down from Shopify in each request.
This image shows how it should look on each request
This image shows how my app behaves
In this image you can see that when you hover the routes no query strings are present, meaning that are passed somehow by the parent app.
As of right now I'm using a Cookie to pass the shopOrigin but I feel like it's not necessary if somehow I'm able to get the query string in each request, also with the HMAC I will be able to verify that the requests are coming from Shopify.
Any calls to your App originating from Shopify properly provide the shop parameter when they make requests. In your own App calls to itself, you would also likely be using the shop name as a query string value.
Note that you are still able to validate your sessions internally using a cookie, you just don't do it via the third-party route, outside the iframe, like we used to. Shopify has plenty of documentation on how to properly authenticate, and construct Apps, check them out. They even give you a working Node App to play with, so you can ensure you get it right.
The solution was pretty straightforward.
Shopify provides a TitleBar AppBridge component that you can use to to handle the App's navigation. What it does is that on each route change it reloads the iframe and the hmac, shop, code and timestamp are coming in the request. It's a tad slower then client side routing but it works as expected.
In order to use it you just need to go to:
Partner's dashboard / Your App / Extensions / Embedded App (click Manage) / Navigation (click Configure) and add navigation links, then you just need to import TitleBar from app-bridge-react and put it in index.js

How should a React app (or any SPA) interact with a HATEOAS back-end?

The basic question is if there should be one HATEOAS entry point per page or one entry point for the entire app?
Most examples I have seen implement a single page with a HATEOAS backend, e.g. a list that is paginated using prev and next links. But what happens when the app navigates to a different page that has completely different capabilities and needs a different entry point? How does one organize such an app?
Concrete example: We have an app with tab navigation. The home tab shows a product catalog so the entry point is /products which returns page 1 of products along with pagination links. However, now I click on the orders tab which must show a list of past orders. This page needs a completely different entry point /orders which the home tab knows nothing about. In fact, user can directly navigate to the orders tab using a deep link.
How to think about this problem? Are there any examples illustrating an approach?
There's a few different ways to solve this. Here's two:
The SPA takes context from the uri (such as an id), and uses it to search on the API. The API can describe templated links/actions to search for resources by their id.
Instead of doing client-side routing, let the server decide what to render.
We're going more towards #2. If we have a uri such as:
https://spa.example/https://api.example/foo/bar
We take the path part of this uri and hit the API. Based on what the API responds with, we decide what to render. This means that most of the routing for these kinds of endpoints is delegated to the server, which feels more in line with HATEOAS.
The path part in this case is an entire absolute URI, but we also support relative uris and have a default base uri. So in practice these two uris are equivalent (for our SPA):
https://spa.example/https://api.example/foo/bar
https://spa.example/foo/bar
We develop & use ketting / react-ketting to do most of the heavy lifting

Rendering Just one module/state of Angular app

I've angular app with lots of states and modules etc. Now, I want to send a link to the user. When user'll hit this url, I want to redirect him to a new tab rendering only that particular state (specified in URL) i-e I don't want anything else to be visible to the user. Or you can say, I want to open a popup window rendering that particular state's html in popup window . This is the approach that comes to my mind to sort it out.
Ps. There are Rest APIs at the backend which I am calling through angular resource service to bind data with the model of the views
Option
I've rest APIs on backend, So, I was thinking to developing s separate Nodejs application, And I will send nodejs application url to the user and in the default/home route I'll call backend API and, the returned resultset will be rendered in html file within nodeJs application and this way, I'll render the corresponding data to user's browser window.
This is the flow for that
I don't know if that is right or clever approach. Please suggest me what will be the best approach to sort it out.
Thanks in advance.
This is what my app looks like
Everything in the left side-nav is a module and clicking on this I am routing to a different state. I am using angular-material and lots of other dependencies in this project.
And this is what I want.
I'll refer a link to the user for example www.myapp.com/specificpage.html. And hitting this url, a new tab/popup will be opened rendering state defined in the same app but with some non-editable url. And it should like.
There are multiple ways to achieve this and each approach has advantage and disadvantage. You have to choose depending on requirement and architecture. Details are below-
Create a separate app - You can do it through separate code base or use the module based build process and include this module only for new app.
Divide application is two part, public pages and private pages - Include this page and required APIs for this page in the public modules for your app.
Send token in the link - If you want to make secure page, send short lived token in the eMail and validate token on the server before displaying page to the user.

Resources