You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 22, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Nov 22, 2024. It is now read-only.
Cloudflare Workers are not compatible with Node.js API, so we can't use Universal express or hapi rendering engines.
The Angular renderer that works in the browser should be compatible in some degree as long as it doesn't use window or document. I'm not sure if the Universal core rendering engine requires Node.js API's to function or if it's possible to run the runtime in a browser.
HTTP
Workers only supports fetch for HTTP requests, where Angular HttpClient I believe uses XMLHttpRequest and jsonp only.
Fetch would need to be integrated into HttpClient or requests intercepted to use fetch.
Build
The build would need a slight change from the one used when building the server.ts currently. It requires target: 'webworker' in the webpack config.
Storage
Serverless doesn't have a filesystem to access. Cloudflare workers use a KV store,
Again because it doesn't support the Node.js API you don't have fs etc. The KV store is where you would store the dist/app-name/browser assets of the Angular app, you would import the @cloudflare/kv-asset-handler package which has methods to retrieve assets, for example, server.ts required dist/app-name/browser/index.html for use in the Universal engine.
I believe I have covered most of the differences when comparing Node.js vs Workers platform.
This universal render should focus on working with service/web workers and not specifically Cloudflare workers. There are other SaaS and open source serverless platforms that are looking to provide a service worker type serverless functions service because of the benefits it has over Node.js runtime. It also might be included in newer JavaScript runtime in the near future that would benefit from this for SSR.
If there's anything that I've overlooked, then please comment.
Reacted by JA, Trey Richards, Jamal El Boutaibi Mohamed, Gaubee, Martin Storgaard Dieu, Ryan Hutchison, Yannic, Dmitry Snytkin, Michael Bromley, max-lt and 4 more
I thought I'd try and accomplish this using CommonEngine but because that imports fs that isn't an option in the current architecture. I think extracting the CommonEngine into a BaseEngine class without any link to the runtime Node.js would allow us to extend or directly use the BaseEngine in our own ServiceWorkersEngine.
I'm still working through the Universal code base to make sure I understand how it all works. I have started to make the custom engine to test out the possibility and to see if anything else comes to light that I may have overlooked. The Angular CLI build now has @angular-devkit/build-angular adding target: "webworker" to the Webpack build process.
Regarding the angular/angular-cli#2305 post, I have already read every comment and couldn't find much traction on that, the feature request is from 2016. I've also scanned every single mention of web worker and service worker throughout the Angular issues without finding much regarding use of web workers to fully render the angular app. I know that @angular/platform-webworker is now deprecated with no mention of an alternative.
Activity
alan-agius4 commentedon Jun 22, 2020
Hi @joejordanbrown,
Thanks for going in such detail 👍
Side note: this is partially related to: angular/angular-cli#2305
joejordanbrown commentedon Jun 22, 2020
Hi @alan-agius4,
I thought I'd try and accomplish this using
CommonEnginebut because that importsfsthat isn't an option in the current architecture. I think extracting theCommonEngineinto aBaseEngineclass without any link to the runtime Node.js would allow us to extend or directly use the BaseEngine in our ownServiceWorkersEngine.I'm still working through the Universal code base to make sure I understand how it all works. I have started to make the custom engine to test out the possibility and to see if anything else comes to light that I may have overlooked. The Angular CLI build now has
@angular-devkit/build-angularaddingtarget: "webworker"to the Webpack build process.Regarding the angular/angular-cli#2305 post, I have already read every comment and couldn't find much traction on that, the feature request is from 2016. I've also scanned every single mention of
web workerandservice workerthroughout the Angular issues without finding much regarding use of web workers to fully render the angular app. I know that@angular/platform-webworkeris now deprecated with no mention of an alternative.My assumption when I read the comment from @filipesilva angular/angular-cli#2305 (comment) was that https://angular.io/guide/web-worker was as far as Angular was willing to integrate Web Workers right now but I may be wrong.
I'll update this issue with any issues I come across.
stewones commentedon Oct 30, 2021
Would love to see Angular moving forward on this. I'm currently having to use a Vue based solution to do SSR on Cloudflare
gp187 commentedon Jun 3, 2023
+1
alan-agius4 commentedon Aug 29, 2023
Let continue tracking this in angular/angular-cli#25718
angular-automatic-lock-bot commentedon Sep 29, 2023
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.