Back
Question
Can we make a domain half static & half dynamic like `/blog` route all static & `/apps` route dynamic ?
I want to make a blog which will use /blog route & use Gatsby which will render a complete static page & then my other route /apps which will have all my apps & their server side logic like Payment on the same domain. Can I make this work like that ? One subdomain renders static pages & another renders dynamic pages ?
👋 Join WIP to participate
Yeah absolutely. You just need to set up your web server (such as Expressjs or Apache) to serve these routes differently.
Will it work for subdomains too? Like blog.a2k.com or will it only work for a2k.com/blog ?
Subdomains and subdirectories are very different things. A subdomain (blog.a2k.com) doesn't need to be on the same server as the root domain (a2k.com). Whereas a subdirectory does. This means that if you're serving something different from a subdomain, it's a lot easier to set up. BUT, subdomains count as separate domains for SEO. So blog.a2k.com is as useful for a2k.com ranking as random2k.com would be.
Thanks didn't knew that. Follow up question. Won't my server get loaded with all my HN traffic on the static page because in turn it runs on an Express Server ?
I setup Express Server & have 2 routes
/static
&/dynamic
& my/static
route just serves static pages but it would still crash my server down if many people visit on my site (/static
route), right ?What I want is if many people are on my
/blog
page it shouldn't affect my server because all my pages are static & it should only get affected if lot of people are on my/apps
page.Your server IS affected. But static routes can be cached, and traffic to a server cache can be freaking huge before it affects you. Also, you can get cloud flare or some other external service to handle that cache, and they can handle Super Bowl amounts of traffic.
Even with HN traffic, you'll be lucky to get shot down. I've run my product (www.blankpage.io) on the smallest Heroku dynamo running Expressjs and I've never been shot down. Despite being first on product hunt etc.
I'll try to make it first. I'm overthinking a lot. If it crashes, then I might change the process or I'll ping you then for advice. For now, I'll be making my
/blog
route a static page running Gatsby &/apps
will contain all my apps. The problem is I don't want to buy 100 domains if I make that many one-of apps. So I'm making one/apps
route which will incorporate all my apps each serving a different dynamic page. Lets see how this goes.I made something similar with PHP a long time ago, you can just trick the server with an index.php (or hbs, js, rb) and redirect to a static page on html/haml in any route you want. Meanwhile, you are still using the rest of your routes as dynamic.
At least with rails and Django is possible or you can just serve all your dynamic app with a subdomain (easy) and done.
Yeah the problem is even if I still serve the static page it will crash my server if traffic is large. Bcz I will be using a server on my domain & from there it will serve a static & a dynamic page but still I need a server. And as Jesper said, it will affect the server but let's see I'm gonna make that shit first. Overthinking is bad & its my favourite habit 😂
I think Gatsby has a solution for this here: www.gatsbyjs.org/docs/buildin…
"A classic example would be a site that has a landing page, various marketing pages, a login page, and then an app section for logged-in users. The logged-in section doesn’t need to be server rendered as all data will be loaded live from your API after the user logs so it makes sense to make this portion of your site client-only."
Wow thanks man. I hope it works. But I need some server for processing Payments, right?
I read it & it means I can have an API which will result in requests/response cycle.
But my use case is I have an
/apps
route containing all my apps. Lets suppose I have aMarkdownViewer.dmg
that I want to show only after Payment is done.If I make this Client only with Gatsby it will show the url at which
MarkdownViewer.dmg
is stored in HTML which will cause people to download without paying. From what you are saying will this work with Gatsby ?And mind you I have seen big companies like Egghead doing it. I found that security issue when they stored all their videos URLs in Redux & I was easily able to download it without a lot of security knowledge.
What I'm referring to is just about the routing (part static, part dynamic). I think that who can access which route doesn't have anything to do with Gatsby – you should handle that yourself.
Oh okk. I don't think it will help for what I am trying to do. What you are saying is like running code on a site which is dynamic. I think I have to make a different server for payment processing & I can send AJAX requests from the Gatsby site. I'll build a prototype to test this idea. It makes sense.