diff --git a/README.md b/README.md index b6bc935..f03df74 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ docker exec -ti angular-universal_nodejs npm install docker exec -ti angular-universal_nodejs bash -c 'npm start' ``` -- in prod mode +- in prod mode (bash deploy.sh as quick solution) ``` docker-compose up -d --build diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..fd211ca --- /dev/null +++ b/deploy.sh @@ -0,0 +1,4 @@ +docker-compose up -d --build +docker exec -ti angular-universal_nodejs npm install +docker exec -ti angular-universal_nodejs bash -c 'npm run build:ssr' +docker exec -ti angular-universal_nodejs bash -c 'npm run serve:ssr' diff --git a/docker/nginx/nginx.conf.dist b/docker/nginx/nginx.conf.dist index 78d9d9b..f5fc68d 100644 --- a/docker/nginx/nginx.conf.dist +++ b/docker/nginx/nginx.conf.dist @@ -41,6 +41,17 @@ http { return 200 "User-agent: *\nDisallow: /\n"; } + error_page 502 /502.html; + + location = /502.html { + try_files 502.html @error; + internal; + } + + location @error { + root /var/www/angular-universal; + } + error_log /var/log/nginx/angular-universal_error.log; access_log /var/log/nginx/angular-universal_access.log; } diff --git a/project/application/angular.json b/project/application/angular.json index 59d63eb..dece6f8 100644 --- a/project/application/angular.json +++ b/project/application/angular.json @@ -13,7 +13,7 @@ "build": { "builder": "@angular-devkit/build-angular:browser", "options": { - "outputPath": "dist/browser", + "outputPath": "tmp/browser", "index": "src/index.html", "main": "src/main.ts", "polyfills": "src/polyfills.ts", @@ -90,7 +90,7 @@ "build": { "builder": "@angular-devkit/build-angular:server", "options": { - "outputPath": "dist/server", + "outputPath": "tmp/server", "main": "src/main.server.ts", "tsConfig": "src/tsconfig.server.json" }, diff --git a/project/application/package.json b/project/application/package.json index 5f82586..57221ec 100644 --- a/project/application/package.json +++ b/project/application/package.json @@ -9,9 +9,10 @@ "lint": "ng lint", "e2e": "ng e2e", "build:ssr": "npm run build:client-and-server-bundles && npm run webpack:server", - "serve:ssr": "pm2 start dist/server.js", + "serve:ssr": "npm run silent:update && pm2 delete -s angular-universal || : && pm2 start dist/server.js --name angular-universal", "build:client-and-server-bundles": "ng run angular-universal--browser:build:production && ng run angular-universal--server:build:production", - "webpack:server": "webpack --config webpack.server.config.js --progress --colors" + "webpack:server": "webpack --config webpack.server.config.js --progress --colors", + "silent:update": "rm -rf dist && cp -r tmp dist && rm -rf tmp" }, "private": true, "dependencies": { diff --git a/project/application/server.ts b/project/application/server.ts index 8787248..799166f 100644 --- a/project/application/server.ts +++ b/project/application/server.ts @@ -18,7 +18,7 @@ const PORT = process.env.PORT || 4000; const DIST_FOLDER = join(process.cwd(), 'dist'); // * NOTE :: leave this as require() since this file is built Dynamically from webpack -const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist/server/main'); +const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./tmp/server/main'); // Import module map for lazy loading import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader'; diff --git a/project/application/src/502.html b/project/application/src/502.html new file mode 100644 index 0000000..97d2ed4 --- /dev/null +++ b/project/application/src/502.html @@ -0,0 +1,11 @@ + + +
+ +Technical work is underway
+ + diff --git a/project/application/webpack.server.config.js b/project/application/webpack.server.config.js index dd9b661..9595d20 100644 --- a/project/application/webpack.server.config.js +++ b/project/application/webpack.server.config.js @@ -9,7 +9,7 @@ module.exports = { // this makes sure we include node_modules and other 3rd party libraries externals: [/node_modules/], output: { - path: path.join(__dirname, 'dist'), + path: path.join(__dirname, 'tmp'), filename: '[name].js', }, module: {