Resource Not Found
+We're sorry. The resource you are looking for cannot be found.
+diff --git a/aio/package.json b/aio/package.json index 47e4e5cf90..7b06930fc3 100644 --- a/aio/package.json +++ b/aio/package.json @@ -57,11 +57,12 @@ "generate-zips": "node ./tools/example-zipper/generateZips", "sw-manifest": "ngu-sw-manifest --dist dist --in ngsw-manifest.json --out dist/ngsw-manifest.json", "sw-copy": "cp node_modules/@angular/service-worker/bundles/worker-basic.min.js dist/", + "build-404-page": "node scripts/build-404-page", "build-ie-polyfills": "yarn webpack-cli src/ie-polyfills.js -o src/generated/ie-polyfills.min.js --mode production", "update-webdriver": "webdriver-manager update --standalone false --gecko false $CHROMEDRIVER_VERSION_ARG", "~~check-env": "node scripts/check-environment", "~~build": "ng build", - "post~~build": "yarn sw-manifest && yarn sw-copy" + "post~~build": "yarn build-404-page && yarn sw-manifest && yarn sw-copy" }, "engines": { "node": ">=8.9.1 <9.0.0", diff --git a/aio/scripts/build-404-page.js b/aio/scripts/build-404-page.js new file mode 100644 index 0000000000..a7147facbb --- /dev/null +++ b/aio/scripts/build-404-page.js @@ -0,0 +1,31 @@ +#!/usr/bin/env node + +// Imports +const {readFileSync, writeFileSync} = require('fs'); +const {join, resolve} = require('path'); + +// Constants +const SRC_DIR = resolve(__dirname, '../src'); +const DIST_DIR = resolve(__dirname, '../dist'); + +// Run +_main(process.argv.slice(2)); + +// Functions - Definitions +function _main() { + const srcIndexPath = join(DIST_DIR, 'index.html'); + const src404BodyPath = join(SRC_DIR, '404-body.html'); + const dst404PagePath = join(DIST_DIR, '404.html'); + + const srcIndexContent = readFileSync(srcIndexPath, 'utf8'); + const src404BodyContent = readFileSync(src404BodyPath, 'utf8'); + const dst404PageContent = srcIndexContent.replace(/
[\s\S]+<\/body>/, src404BodyContent); + + if (dst404PageContent === srcIndexContent) { + throw new Error( + 'Failed to generate \'404.html\'. ' + + 'The content of \'index.html\' does not match the expected pattern.'); + } + + writeFileSync(dst404PagePath, dst404PageContent); +} diff --git a/aio/src/404-body.html b/aio/src/404-body.html new file mode 100644 index 0000000000..8b9185c228 --- /dev/null +++ b/aio/src/404-body.html @@ -0,0 +1,52 @@ + + + + +We're sorry. The resource you are looking for cannot be found.
+