Skip to content

Commit

Permalink
feat: added api proxying and rewrite configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
dereekb committed May 27, 2022
1 parent 25ddc4e commit 0117dae
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 13 deletions.
2 changes: 2 additions & 0 deletions apps/demo/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@
"configurations": {
"production": {
"browserTarget": "demo:build-base:production",
"proxyConfig": "apps/demo/proxy.conf.prod.json",
"port": 9010
},
"development": {
"browserTarget": "demo:build-base:development",
"proxyConfig": "apps/demo/proxy.conf.dev.json",
"port": 9010
}
},
Expand Down
7 changes: 7 additions & 0 deletions apps/demo/proxy.conf.dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"/api/*": {
"target": "http://0.0.0.0:9902",
"secure": false,
"logLevel": "debug"
}
}
7 changes: 7 additions & 0 deletions apps/demo/proxy.conf.prod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"/api/*": {
"target": "https://components.dereekb.com/api",
"secure": true,
"logLevel": "debug"
}
}
22 changes: 11 additions & 11 deletions firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
"site": "dereekb-components",
"public": "dist/apps/demo",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"headers": [
{
"source": "*.[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].+(css|js)",
"headers": [
{
"key": "Cache-Control",
"value": "public,max-age=31536000,immutable"
}
]
}
],
"headers": [{
"source": "*.[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].+(css|js)",
"headers": [{
"key": "Cache-Control",
"value": "public,max-age=31536000,immutable"
}]
}],
"rewrites": [
{
"source": "/api/**",
"function": "api"
},
{
"source": "**",
"destination": "/index.html"
Expand Down
13 changes: 11 additions & 2 deletions setup/setup-project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ rm -r functions
# edit firebase.json to have the correct configuration.

# Hosting
npx --yes json -I -f firebase.json -e "this.hosting={ ...this.hosting, site: '$PROJECT_NAME', public: '$ANGULAR_APP_DIST_FOLDER', ignore: ['firebase.json', '**/.*', '**/node_modules/**'], rewrites: [{ source: '**', destination: '/index.html' }] }";
npx --yes json -I -f firebase.json -e "this.hosting={ ...this.hosting, site: '$PROJECT_NAME', public: '$ANGULAR_APP_DIST_FOLDER', ignore: ['firebase.json', '**/.*', '**/node_modules/**'], rewrites: [{ source: '/api/**', function: 'api' }, { source: '**', destination: '/index.html' }] }";

# Functions
npx --yes json -I -f firebase.json -e "this.functions={ source:'$API_APP_DIST_FOLDER', runtime: 'nodejs16', engines: { node: '16' }, ignore: ['firebase.json', '**/.*', '**/node_modules/**'] }";
Expand Down Expand Up @@ -327,7 +327,7 @@ update_jest_config_file "$ANGULAR_COMPONENTS_FOLDER"
update_jest_config_file "$FIREBASE_COMPONENTS_FOLDER"

# add env files to ensure that jest CI tests export properly.
mkdir tmp # TODO: Change from /develop to /main later.
mkdir tmp
curl https://raw.githubusercontent.com/dereekb/dbx-components/$SOURCE_BRANCH/setup/templates/apps/.env -o tmp/env.tmp
sed -e "s/APP_ID/$ANGULAR_APP_NAME/g" tmp/env.tmp > $ANGULAR_APP_FOLDER/.env
sed -e "s/APP_ID/$API_APP_NAME/g" tmp/env.tmp > $API_APP_FOLDER/.env
Expand Down Expand Up @@ -470,6 +470,15 @@ download_angular_ts_file "src/main.ts"
download_angular_ts_file "src/root.module.ts"
download_angular_ts_file "src/root.firebase.module.ts"

# proxy.conf.dev.json
curl https://raw.githubusercontent.com/dereekb/dbx-components/$SOURCE_BRANCH/apps/demo/src/proxy.conf.dev.json -o $ANGULAR_APP_FOLDER/src/proxy.conf.dev.json.tmp
sed -e "s/9902/$FIREBASE_EMULATOR_AUTH_PORT/g" $ANGULAR_APP_FOLDER/src/proxy.conf.dev.json.tmp > $ANGULAR_APP_FOLDER/src/proxy.conf.dev.json
rm $ANGULAR_APP_FOLDER/src/proxy.conf.dev.json.tmp

curl https://raw.githubusercontent.com/dereekb/dbx-components/$SOURCE_BRANCH/apps/demo/src/proxy.conf.prod.json -o $ANGULAR_APP_FOLDER/src/proxy.conf.prod.json.tmp
sed -e "s-components.dereekb.com-example.dereekb.com-g" $ANGULAR_APP_FOLDER/src/proxy.conf.prod.json.tmp > $ANGULAR_APP_FOLDER/src/proxy.conf.prod.json
rm $ANGULAR_APP_FOLDER/src/proxy.conf.prod.json.tmp

# lib
mkdir $ANGULAR_APP_FOLDER/src/lib
curl https://raw.githubusercontent.com/dereekb/dbx-components/$SOURCE_BRANCH/apps/demo/src/lib/segment.js -o $ANGULAR_APP_FOLDER/src/lib/segment.js
Expand Down
2 changes: 2 additions & 0 deletions setup/templates/apps/app/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@
"configurations": {
"production": {
"browserTarget": "ANGULAR_APP_NAME:build-base:production",
"proxyConfig": "apps/ANGULAR_APP_NAME/proxy.conf.prod.json",
"port": ANGULAR_APP_PORT
},
"development": {
"browserTarget": "ANGULAR_APP_NAME:build-base:development",
"proxyConfig": "apps/ANGULAR_APP_NAME/proxy.conf.dev.json",
"port": ANGULAR_APP_PORT
}
},
Expand Down
4 changes: 4 additions & 0 deletions setup/templates/firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
}
],
"rewrites": [
{
"source": "/api/**",
"function": "api"
},
{
"source": "**",
"destination": "/index.html"
Expand Down

0 comments on commit 0117dae

Please sign in to comment.