Skip to content

Commit

Permalink
reran firebase init and added functions
Browse files Browse the repository at this point in the history
  • Loading branch information
timofeysie committed Sep 8, 2021
1 parent 731a208 commit c15ec5e
Show file tree
Hide file tree
Showing 10 changed files with 3,575 additions and 8 deletions.
38 changes: 37 additions & 1 deletion docs/trendy-ssr.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,46 @@ Here are some notes about SSR.
- events other than routerLink clicks aren't supported. You must wait for the full client application to bootstrap and run,
- Any web server technology can serve a Universal application as long as it can call Universal's renderModule() function.
- Universal applications use the Angular platform-server package (as opposed to platform-browser), which provides server implementations of the DOM, XMLHttpRequest, and other low-level features that don't rely on a browser.
- passes client requests for application pages to the NgUniversal ngExpressEngine. Under the hood, this calls Universal's renderModule() function, while providing caching and other helpful utilities.
- passes client requests for application pages to the NgUniversal ngExpressEngine. Under the hood, this calls Universal's renderModule() function, while providing caching and other helpful utilities.
- The renderModule() function takes as inputs a template HTML page (usually index.html), an Angular module containing components, and a route that determines which components to display. The route comes from the client's request to the server.
- The ngExpressEngine() function is a wrapper around Universal's renderModule()
- Angular provides some injectable abstractions over these objects, such as Location or DOCUMENT; it may substitute adequately for these APIs
- server-side applications can't reference browser-only global objects such as window, document, navigator, or location.
So we need something to call the renderModule() function. Going to try the Deploy to Firebase using Functions and Hosting step from [this article](https://dipesious.medium.com/angular-11-universal-firebase-deployment-300047b988aa) by Dipesh Bhoir
Before, functions was not an option because it was behind a paywall. Since that wall has been breached, its time to go there.
That means running firebase init again. The files such as firebase.json had to be moved from the app/trendy directory last time to work, so will have to do that again. The command for nx will be.
nx run trendy:firebase --cmd=init
When it asks this question:
```txt
? Configure as a single-page app (rewrite all urls to /index.html)?
```
According to [a SO answer]() *if you would like to have Server-Side Rendering (SSR), type No and set up your rewrites as follow:*
```js
"rewrites": [
{
"function": "angularUniversalFunction",
"source": "**"
}
]
```
The Dipesh Bhoir article shows doing this:
```js
"rewrites": [
{
"source": "**",
"function": "ssr"
}
]
```
Funny that that rewrites section was completely removed by the init and replaced with a functions section. Guess we need both?
14 changes: 7 additions & 7 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"hosting": {
"public": "dist/apps/trendy/browser",
"public": "dist/apps/trendy",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"function": "ssr"
}
]
},
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
}
31 changes: 31 additions & 0 deletions functions/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = {
root: true,
env: {
es6: true,
node: true,
},
extends: [
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"google",
"plugin:@typescript-eslint/recommended",
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: ["tsconfig.json", "tsconfig.dev.json"],
sourceType: "module",
},
ignorePatterns: [
"/lib/**/*", // Ignore built files.
],
plugins: [
"@typescript-eslint",
"import",
],
rules: {
"quotes": ["error", "double"],
"import/no-unresolved": 0,
},
};
9 changes: 9 additions & 0 deletions functions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Compiled JavaScript files
lib/**/*.js
lib/**/*.js.map

# TypeScript v1 declaration files
typings/

# Node.js dependency directory
node_modules/
9 changes: 9 additions & 0 deletions functions/cp-angular.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const fs = require('fs-extra');

(async () => {
const src = '../dist';
const copy = './dist';

await fs.remove(copy);
await fs.copy(src, copy);
})();
Loading

0 comments on commit c15ec5e

Please sign in to comment.