Skip to content

Commit

Permalink
feat: serve robots.txt from universal server (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian-Haehnlein authored and dhhyi committed Jan 9, 2020
1 parent 85c8cb2 commit 34bbd04
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# compiled or cached output
/dist/**/*
!/dist/*.sh
!/dist/healthcheck.js
/tmp
/out-tsc
/bin
Expand Down
5 changes: 5 additions & 0 deletions dist/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**/*
!/.gitignore
!/*.sh
!/healthcheck.js
!/robots.txt
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"conventional-changelog-cli": "^2.0.21",
"core-js": "^2.6.9",
"express": "^4.17.1",
"express-robots-txt": "0.4.1",
"lodash-es": "^4.17.15",
"ng-recaptcha": "^5.0.0",
"ng2-validation": "^4.2.0",
Expand Down
27 changes: 27 additions & 0 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import 'zone.js/dist/zone-node';

import * as express from 'express';
import { join } from 'path';
import * as robots from 'express-robots-txt';
import * as fs from 'fs';

const logging = !!process.env.LOGGING;

Expand All @@ -44,6 +46,31 @@ app.engine(
app.set('view engine', 'html');
app.set('views', join(DIST_FOLDER, 'browser'));

// seo robots.txt
const pathToRobotsTxt = join(DIST_FOLDER, 'robots.txt');
if (fs.existsSync(pathToRobotsTxt)) {
app.use(robots(pathToRobotsTxt));
} else {
app.use(
robots({
UserAgent: '*',
Disallow: [
'/error',
'/account',
'/compare',
'/recently',
'/basket',
'/checkout',
'/register',
'/login',
'/logout',
'/forgotPassword',
'/contact',
],
})
);
}

// Serve static files from /browser
app.get(
'*.*',
Expand Down

0 comments on commit 34bbd04

Please sign in to comment.