Skip to content

Commit

Permalink
Add robots.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarski committed Oct 27, 2019
1 parent 54e33be commit f7d4a7e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();

const robots = `User-agent: *
Allow: /
Host: https://luck.org.pl
`;

app.prepare().then(() => {
createServer((req: { url: any }, res: any) => {
// Be sure to pass `true` as the second argument to `url.parse`.
Expand All @@ -19,6 +24,10 @@ app.prepare().then(() => {

if (pathname === '/posts' || pathname === '/posty') {
app.render(req, res, '/blog', query);
} else if (pathname === '/robots.txt') {
res.statusCode = 200;
res.write(robots);
res.end();
} else {
handle(req, res, parsedUrl);
}
Expand Down

0 comments on commit f7d4a7e

Please sign in to comment.