diff --git a/apps/demo/project.json b/apps/demo/project.json index 8f58e5d08..71e4961d7 100644 --- a/apps/demo/project.json +++ b/apps/demo/project.json @@ -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 } }, diff --git a/apps/demo/proxy.conf.dev.json b/apps/demo/proxy.conf.dev.json new file mode 100755 index 000000000..be6eaf516 --- /dev/null +++ b/apps/demo/proxy.conf.dev.json @@ -0,0 +1,7 @@ +{ + "/api/*": { + "target": "http://0.0.0.0:9902", + "secure": false, + "logLevel": "debug" + } +} diff --git a/apps/demo/proxy.conf.prod.json b/apps/demo/proxy.conf.prod.json new file mode 100755 index 000000000..732bc813c --- /dev/null +++ b/apps/demo/proxy.conf.prod.json @@ -0,0 +1,7 @@ +{ + "/api/*": { + "target": "https://components.dereekb.com/api", + "secure": true, + "logLevel": "debug" + } +} diff --git a/firebase.json b/firebase.json index d1afc1736..c723fb02b 100644 --- a/firebase.json +++ b/firebase.json @@ -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" diff --git a/setup/setup-project.sh b/setup/setup-project.sh index 640d523c7..95422a4c3 100755 --- a/setup/setup-project.sh +++ b/setup/setup-project.sh @@ -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/**'] }"; @@ -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 @@ -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 diff --git a/setup/templates/apps/app/project.json b/setup/templates/apps/app/project.json index 7962b13d1..3e557f7e3 100644 --- a/setup/templates/apps/app/project.json +++ b/setup/templates/apps/app/project.json @@ -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 } }, diff --git a/setup/templates/firebase.json b/setup/templates/firebase.json index 225aa3223..e7c59b1d7 100644 --- a/setup/templates/firebase.json +++ b/setup/templates/firebase.json @@ -19,6 +19,10 @@ } ], "rewrites": [ + { + "source": "/api/**", + "function": "api" + }, { "source": "**", "destination": "/index.html"