No video

Angular Universal on Cloud Functions or AppEngine

  Рет қаралды 33,045

Fireship

Fireship

5 жыл бұрын

Learn how to perform serverside rendering (SSR) with Angular Universal, then deploy to Firebase Cloud Functions or GCP AppEngine fireship.io/lessons/angular-u... for better perf and SEO
Universal - angular.io/guide/universal
Functions - firebase.google.com/docs/func...
GCP cloud.google.com/sdk

Пікірлер: 106
@TheSoruzz
@TheSoruzz 3 жыл бұрын
For everyone using this tutorial when using Angular 9+, some things have changed (e.g. server.ts etc). This is what worked for me: My functions now created a folder structure of dist/[PROJECT_NAME]/browser (and /server), and no server.js anymore. - In the index.ts of your functions, be sure that the path after process.cwd() is correct. In my case I changed 'dist/server' to 'dist/[PROJECT_NAME]/server/main' - In your server.ts, in the video he commented out the server.listen. In the new angular version you can remove the run() function (or comment out the run() call) Note: If you first add angular universal and after that add angular/fire, it automatically asks if you want to add a ssr function (great for new projects)
@zoecarlibur
@zoecarlibur 5 жыл бұрын
I've watched several Angular universal videos and read several articles on it. They all made it seem like a big deal. This was broken down so beautifully. Well done Jeff!
@Fireship
@Fireship 5 жыл бұрын
Thank you, it's one of those things that used to be hard, but `ng add` makes it way easier now.
@LarsRyeJeppesen
@LarsRyeJeppesen 4 жыл бұрын
@@Fireship It's stil hard if you have i18n, ie. multiple translations
@airxperimentboom
@airxperimentboom 10 ай бұрын
Any update in 2023 for i18n + SSR
@n3nikita
@n3nikita 4 жыл бұрын
How can I deploy Angular 9 Universal on Cloud Functions?
@JancoBH
@JancoBH 5 жыл бұрын
OMG Finally 😍😍 I have been waiting for it like for 1 year 🤣 thank you so much, you are the best
@Fireship
@Fireship 5 жыл бұрын
Made this one for you!
@JancoBH
@JancoBH 5 жыл бұрын
@@Fireship Really? 🤣,Thanks 😍
@crycetruly
@crycetruly 5 жыл бұрын
@@Fireship Hahahaha even me.
@almshakeel
@almshakeel 2 жыл бұрын
omg u saved my life finally great source talk about SSR thank you so much
@kevind2154
@kevind2154 5 жыл бұрын
Great video as always, thanks a lot!
@danielguzman8607
@danielguzman8607 4 жыл бұрын
You just saved my life, man! *-* Thanks!!!
@pandarzzz
@pandarzzz 5 жыл бұрын
Thank you for sharing this informative lesson! I wish you well.
@Fireship
@Fireship 5 жыл бұрын
Thank you Kevin :)
@p2rt
@p2rt 5 жыл бұрын
In package.json, why have "npm run serve:ssr" under start, why not just have "node dist/server" right away?
@AbhishekKumar-mq1tt
@AbhishekKumar-mq1tt 5 жыл бұрын
Thank u for this awesome video
@ikezedev
@ikezedev 5 жыл бұрын
Boss, nice one!
@SaadAbbasi
@SaadAbbasi 5 жыл бұрын
Everything Great explained
@elmotareal
@elmotareal 4 жыл бұрын
Question: firebase seves index.html (the static one) as a preference to ssr function, how did you get over that? personally I changed index.html name, but how did you do it?
@hformin
@hformin 4 жыл бұрын
Very helpful
@kkmm731
@kkmm731 4 жыл бұрын
Can someone please help me? I have an angular 9 project, everything works fine till build and serve ssr but when i try to firebase serve, it says module not found, i did not see any server.config generated file and my server.ts file is changed as well in angular 9.
@himagirilb
@himagirilb 5 жыл бұрын
Hi, I have two projects say 'public' and 'admin' created under a single Angular app/workspace. Now I am trying to add Angular Universal to 'public' project alone. I followed the steps as you mentioned in your video. I got the below error when I tried to build ssr. $ npm run build:ssr --project public > /main-app/src/environments/environment.prod.ts path in file replacements does not exist. Is there anything I need to do to get rid of this error? Please advise.
@AlessandroTaricani
@AlessandroTaricani 5 жыл бұрын
Great video as always .. I will definitely look into! P.S. love your examples with unicorns and NBA
@Fireship
@Fireship 5 жыл бұрын
Glad you caught that, but Michael Jordan was a MLB baseball player www.baseball-reference.com/bullpen/Michael_Jordan
@AlessandroTaricani
@AlessandroTaricani 5 жыл бұрын
@@Fireship I think that every time someone talk about the MLB period... a NBA fan die xD
@LarsKniep
@LarsKniep 5 жыл бұрын
Liked!
@malchik12
@malchik12 5 жыл бұрын
Can't wait to try this out! @jeff do u have any idea how get Google to index user profiles dynamically created from firebase and my angular app?
@umka7873
@umka7873 5 жыл бұрын
Hi Jeff, tell me pls, what a track play at the beggining ?
@Synkto01
@Synkto01 5 жыл бұрын
Hi Jef, I have two questions, how can we use LINKS for 'canonical' and 'alternate' in SEO, if import { DOCUMENT } from '@angular/common' is now Deprecated?. Ex: @Inject(DOCUMENT) private doc ... let link: HTMLLinkElement = this.doc.createElement('link'); link.setAttribute('rel', 'canonical'); this.doc.head.appendChild(link); link.setAttribute('href', this.doc.URL); ... And second, I'm using Angular Material and in some cases I have to tweak a little bit the components, in some case for the shadow DOM, I can´t do it with scss, I have to use ElementRef for searching the element and then I use Renderer2, to apply the style. Is there any risk to do this?...I read about some security problems with ElementRef but when you apply styles directly with ElementRef. Ex: const listItems = this.elementRef.nativeElement.querySelectorAll('.mat-expansion-panel-body') as HTMLElement[]; listItems.forEach(listItem => { this.renderer.setStyle(listItem, 'padding', '0px'); }); I really will apreciate your answer. Keep the good work!!
@the.maciota
@the.maciota 5 жыл бұрын
I caught in the "firebase init" part it does not create the functions folder :/ please help me ? i do not speak english...Maybe you give some hint and I did not understand.
@andriesvanwyk3226
@andriesvanwyk3226 5 жыл бұрын
Thank you for the great tutorial, Jeff! Would you mind clarifying something for me please, as I'm having a hard time finding concrete answers... I currently have an Angular app that makes http calls to a PHP REST API. Q: Do I need to rewrite my entire PHP API to Nodejs when adding Universal to my Angular app? Or do I simply add Universal, and my app still communicates with the PHP API as it is now? Does Universal merely 'intercept' http responses? Q2: When deploying to a live server, I assume I'll need to execute 'npm run server.js' ... But when I update the server, do I need to stop and restart that service every time? Would really appreciate a clear answer, many thanks!
@airxperimentboom
@airxperimentboom 2 жыл бұрын
Did you find the answer?
@tohedul111
@tohedul111 3 жыл бұрын
Can you please explain how can I use global variables (localStorage, window etc) in ssr?
@franfonse
@franfonse 4 жыл бұрын
I just got my GCP free 12 month trial but I don't think it includes Firebase hosting... it says my plan is Spark in there :/
@vijayhardaha
@vijayhardaha 4 жыл бұрын
Do you have public repository for this to review the code?
@manojisaac
@manojisaac 5 жыл бұрын
These additional steps are required: Error: You must pass in a NgModule or NgModuleFactory to be bootstrapped Fix: 13865 npm i @angular-devkit/build-angular@0.13.4 cd functions npm install --save firebase-functions npm install --save firebase-admin@~7.0.0 Great work Fireship.. David east has shown how to write to CDN for dynamic ssr, then web worker will load it from cache from next time onwards, Also do we have a comprehensive video on pwa?
@piezasweb7145
@piezasweb7145 5 жыл бұрын
This was magical, excellent explanation. I have a question, in the case of firebase cloud functions... when making an HTTP request to some API to bring dynamic data and render it from the server, How can I do that ?, Since I tried it but the request is not made in the server and the data does not appear in the source code Can you help me with that?
@JancoBH
@JancoBH 5 жыл бұрын
I had to back to rendertron for now, 😥 I recived in Cloud Functions registers "Discarding entity body for GET requests" and "Error: memory limit exceeded. Function invocation was interrupted." I have to search how to fix it, I think that is hard apply this in an existing app that is using many things.
@Fireship
@Fireship 5 жыл бұрын
Interesting, thanks for reporting. This was a bare minimum example, so there could be many gotchas. I'm started a guide that can hopefully provide workarounds for issues like this fireship.io/snippets/angular-universal-ssr-cookbook/
@JancoBH
@JancoBH 5 жыл бұрын
​@@Fireship thanks for your response, those errors like "window or document is nor defined" I knew how to solve that, I got many others errors for example something like this (stackoverflow.com/questions/48139457/firebase-gives-path-not-recognized-error-for-post-requests) when I tried to change the route (my app uses LazyLoad routing) (I think that I solves this changing all the images routes from ./../assets/etc.. to assets/) today when i back from work I will try again 👍 thanks again for your hard work
@shyagam
@shyagam 4 жыл бұрын
Any thoughts on why my app-root might be empty still?
@viktorkhyzhniak8103
@viktorkhyzhniak8103 4 жыл бұрын
did you solve this problem?
@HSDevStudio
@HSDevStudio 5 жыл бұрын
Hi Jeff, really helpful. Can we have a couple of videos on angular library or custom schematics
@Fireship
@Fireship 5 жыл бұрын
I like that idea, schematics has been on my list forever. It is a challenging topic to cover.
@HSDevStudio
@HSDevStudio 5 жыл бұрын
@@Fireship I firmly believe you can do it. :-)
@josejeanton4436
@josejeanton4436 5 жыл бұрын
i have trouble with the "firebase external" config... work perfect on localhost, but were i deploy, throw me error, Error: Cannot find module 'firebase/app', and if i remove this, it does not work, because does not load the data from firestore. Some help?
@LarsRyeJeppesen
@LarsRyeJeppesen 4 жыл бұрын
I think you need to be on the "Blaze" plan to request external data
@elmotareal
@elmotareal 4 жыл бұрын
you know you can change webpack to place the output directly in functions/dist, it will have the bare bone in /dist, but that file is not needed for universal
@RussianBritish
@RussianBritish 5 жыл бұрын
Interesting... We use prerendering and cashing for our app.. Gotta calculate the cost of app engine vs cloud finction when it comes to significant traffic... Currently we pays only 15 bucks a month fir prerendering. And yet I'm impressed, where do u pall find times for everything?
@Fireship
@Fireship 5 жыл бұрын
If your content does not change frequently then prerendering is great - that's what I do for fireship.io w/ ng elements.
@sagarvd35
@sagarvd35 4 жыл бұрын
Great one. well explained. I've a problem with firebase deploy. I can load the home page and from there, I can navigate to any page. But when I enter an absolute path or reload browser, it throw error "could not handle request" and in firebase console, I can see an error "Typeerror: handler is not a function". Any idea how to solve this?
@sagarvd35
@sagarvd35 4 жыл бұрын
Here's the link to github issue github.com/firebase/firebase-tools/issues/1705 which contains full details
@vidhyanshujain6221
@vidhyanshujain6221 5 жыл бұрын
I can't see the index.html file in my dist folder. Any Idea what could have happened?
@bryanfischbach8486
@bryanfischbach8486 5 жыл бұрын
this solved it for me. index.ts export const ssr = functions.https.onRequest((request, response) => { require(`${process.cwd()}/dist/server`).app(request, response); });
@limjason8132
@limjason8132 2 жыл бұрын
Skipping installation: Package already installed Unknown option: '--clientProject' Unknown option: 'blk-design-system-angular' how to solve this?
@airxperimentboom
@airxperimentboom 10 ай бұрын
Any 2023 update for SSR + Angular + i18n ?
@kunalkakkad4790
@kunalkakkad4790 5 жыл бұрын
Hello, After following all the defined steps I was able to deploy the app. But still it is not deployed as a Universal version as in after deployment when I view source then it is showing only Kindly if anyone can help it out then it would be better.
@MrGuysmo92
@MrGuysmo92 4 жыл бұрын
Same for me
@johnbuchmann4912
@johnbuchmann4912 4 жыл бұрын
Same... not sure if it's the same problem, but "other" routes do work fine. For example, the /about route is server side rendered. But the home route (/) isn't, and it's driving me nuts. Been at this for a couple days with no solution in sight. :(
@nemanjasubotin5465
@nemanjasubotin5465 5 жыл бұрын
Nice video, thanks. What if i have spring boot server and mysqldb along with angular frontend application, is it possible to build docker container out of those and deploy to google cloud for free?
@Fireship
@Fireship 5 жыл бұрын
You have to use the standard runtime images for the free tier, it sounds like you need the flexible env which will cost $.
@nemanjasubotin5465
@nemanjasubotin5465 5 жыл бұрын
@@Fireship Ill figure something out, thanks ^^
@kanhaiyasinghsanger
@kanhaiyasinghsanger 3 жыл бұрын
Hi Title and meta serving through api not showing in view source. How can we solve this issue
@josuebarrantes2484
@josuebarrantes2484 3 жыл бұрын
any luck with this?
@ankitbhanderi2424
@ankitbhanderi2424 4 жыл бұрын
ssr is not working on cloud function. Even I followed all the steps and even page view source come up with empty app-root.
@chrisoppedal5329
@chrisoppedal5329 4 жыл бұрын
Same here, were you able to get this to work?
@ankitbhanderi2424
@ankitbhanderi2424 4 жыл бұрын
@@chrisoppedal5329 yes
@jonathancramer8651
@jonathancramer8651 4 жыл бұрын
@@ankitbhanderi2424 care to explain how?
@ttbooster
@ttbooster 4 жыл бұрын
Baseball or basketball?
@trishalim9029
@trishalim9029 4 жыл бұрын
Are the Facebook og meta tags actually working for anyone?
@BogacGuven
@BogacGuven 5 жыл бұрын
How Universal compare to Puppeteer solution in your experience?
@Fireship
@Fireship 5 жыл бұрын
Universal performs faster, but it is harder to setup and easy to break if you touch the DOM directly.
@BogacGuven
@BogacGuven 5 жыл бұрын
@@Fireship That's what I was thinking as well 👍...thanks
@troythompson2
@troythompson2 5 жыл бұрын
Jeff you are a fucking machine
@manojht8036
@manojht8036 5 ай бұрын
Hello, no offense but things changed now, would you be kind enough to redo this for new angular ssr? it would be really nice. i know you like angular
@ttbooster
@ttbooster 4 жыл бұрын
hello I followed the tutorial on fireship.io/lessons/angular-universal-firebase/ step by step. I want to deploy to Firebase Hosting with Firebase Cloud Functions For some reason the npm run serve:ssr is not delivering the same result as firebase serve.. The firebase serve command is not pre-rendering the html. It only delivers the blank html page with , whereas the npm run serve:ssr delivers the full html as in the video.. I'm running Angular 8 and not 7 as in the video. The other difference is that I have Node v10.16.3 installed and not Node 8.14 as recommended in the video but once uploaded by firebase deploy, it shouldn't make a difference I guess.. What do I do to get the pre_render on Firebase??
@elmotareal
@elmotareal 5 жыл бұрын
So are you saying if we use jquery we can't use universal?
@Fireship
@Fireship 5 жыл бұрын
It may cause problems. You can use platform checking to only run jquery in the browser github.com/angular/universal-starter/issues/482
@LeoN11rus
@LeoN11rus 5 жыл бұрын
I used hammerjs, and nguniversal gave me error about 'window is not defined', then I moved import 'hammerjs'; to main.ts file and after that it works fine, I guess with JQuery its the same thing. But maybe there is a better approach
@elmotareal
@elmotareal 5 жыл бұрын
@@LeoN11rus do you mean main.server.ts? because main.ts is not included in server build, and without jquery a lot of code renders invalid
@LeoN11rus
@LeoN11rus 5 жыл бұрын
@@elmotareal yes, you are right
@mrsasan9016
@mrsasan9016 3 жыл бұрын
Can you share soundtracks please? Thanks
@jajaperson
@jajaperson 5 жыл бұрын
Can you do a video on NestJS?
@ttbooster
@ttbooster 4 жыл бұрын
throw new Error("package.json does not exist at " + package_json_path);
@macaroni_boy
@macaroni_boy 4 жыл бұрын
Same
@ttbooster
@ttbooster 4 жыл бұрын
@@macaroni_boyI solved it by installing @types/node in the root and add "node" to types
@ttbooster
@ttbooster 4 жыл бұрын
install @types/node in root add "node" to compilerOptions.types array in tsconfig.app.json
@alitonoliveira1700
@alitonoliveira1700 3 жыл бұрын
So for SSR... if we want to run a node app with high demand, we should use App Engine, but if we want to run a node app with low demand, we should do hacking and use Cloud Function plus Firebase Hosting.
@kevinl.9657
@kevinl.9657 3 жыл бұрын
I'm not sure and I'm still researching, but I think Cloud Run is better to use now. You can also use it with Firebase Hosting. But hey, don't take my word for it. Fireship has video about this here kzfaq.info/get/bejne/abWAYNRmms6zhX0.html
@alitonoliveira1700
@alitonoliveira1700 3 жыл бұрын
@@kevinl.9657 No problem
@bryanfischbach8486
@bryanfischbach8486 5 жыл бұрын
fixed firebase deploy with index.ts export const ssr = functions.https.onRequest((request, response) => { require(`${process.cwd()}/dist/server`).app(request, response); });
@metalllus
@metalllus 4 жыл бұрын
thnx, this works.
@Zoomink
@Zoomink 5 жыл бұрын
Baseball? 🤔😊
@Fireship
@Fireship 5 жыл бұрын
One of the greatest players to ever throw a pitch 😉 www.baseball-reference.com/bullpen/Michael_Jordan
@SaadAbbasi
@SaadAbbasi 5 жыл бұрын
Video didn't work
@oldfootage
@oldfootage 4 жыл бұрын
The functions portion of this video is now useless. server.ts is unrecognizable. Looks nothing like the current version.
@darshangowda309
@darshangowda309 5 жыл бұрын
first :P
@Fireship
@Fireship 5 жыл бұрын
🥇 gold
@marcellokabora
@marcellokabora 5 жыл бұрын
Useless if cannot render data from the database.
@LarsRyeJeppesen
@LarsRyeJeppesen 4 жыл бұрын
You can..
@creativa5140
@creativa5140 5 жыл бұрын
confundes mucho men
Angular SEO with Rendertron
13:47
Fireship
Рет қаралды 44 М.
Run your Angular app on Google Cloud
17:10
Google Cloud Tech
Рет қаралды 7 М.
UNO!
00:18
БРУНО
Рет қаралды 2,8 МЛН
1,000 Diamonds! (Funny Minecraft Animation) #shorts #cartoon
00:31
toonz CRAFT
Рет қаралды 40 МЛН
Опасность фирменной зарядки Apple
00:57
SuperCrastan
Рет қаралды 12 МЛН
How programmers flex on each other
6:20
Fireship
Рет қаралды 2,3 МЛН
Modern Angular deployment with Google Cloud
13:08
Google Cloud Tech
Рет қаралды 13 М.
Why Monthly Home Payments Are Skyrocketing Right Now
8:48
I built the same app 10 times // Which JS Framework is best?
21:58
Fireship
Рет қаралды 2,5 МЛН
Advanced Angular Elements
11:46
Fireship
Рет қаралды 64 М.
💥 Angular SSR Deep Dive (With Client HYDRATION) #angular
24:56
Angular University
Рет қаралды 15 М.
Nuclear waste is reusable. Why aren’t we doing it?
15:25
DW Planet A
Рет қаралды 284 М.
UNO!
00:18
БРУНО
Рет қаралды 2,8 МЛН