Skip to content

Commit

Permalink
fix(robots.txt): Disallow all on dev envs
Browse files Browse the repository at this point in the history
  • Loading branch information
olemathias committed Oct 21, 2024
1 parent 00e959d commit eea721b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions .env.runtime
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# https://docs.astro.build/en/guides/integrations-guide/node/#runtime-environment-variables
# Variables that should be loaded on runtime and not during build is added here, the value is not used for anything
API_URL=placeholder
SITE_URL=placeholder
MATOMO_SITE_ID=placeholder
MATOMO_INSTANCE_URL=placeholder
4 changes: 0 additions & 4 deletions public/robots.txt

This file was deleted.

1 change: 1 addition & 0 deletions src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

interface ImportMetaEnv {
readonly API_URL: string;
readonly SITE_URL: string;
readonly MATOMO_SITE_ID: string;
readonly MATOMO_INSTANCE_URL: string;
}
4 changes: 1 addition & 3 deletions src/pages/liveness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export const prerender = false;

/**
* GET Request with JSON response
* @returns {Response}
*/
export async function GET() {
return new Response(JSON.stringify({ alive: true }), {
Expand All @@ -14,8 +13,7 @@ export async function GET() {
}

/**
* HEAD Request
* @returns {Response}
* HEAD Request. Just return 204
*/
export function HEAD() {
return new Response(null, {
Expand Down
25 changes: 25 additions & 0 deletions src/pages/robots.txt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export const prerender = false;

import.meta.env.SITE_URL;

var prod_robots = `User-agent: *
Disallow: /api/
Disallow: /admin/
Disallow: /django-admin/`;

var dev_robots = `User-agent: *
Disallow: /`;

/**
* GET Request
*/
export async function GET() {
if (import.meta.env.SITE_URL == "https://www.tg.no/") {
return new Response(prod_robots, {
status: 200,
});
}
return new Response(dev_robots, {
status: 200,
});
}

0 comments on commit eea721b

Please sign in to comment.