Skip to content

Commit

Permalink
Merge pull request #101 from sgcarstrends/100-allowdisallow-indexing-…
Browse files Browse the repository at this point in the history
…based-on-app-environment

Allow/disallow indexing based on app environment
  • Loading branch information
ruchernchong authored Aug 19, 2024
2 parents 985e283 + c5151d7 commit 5c3da19
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
26 changes: 18 additions & 8 deletions app/robots.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import { SITE_URL } from "@/config";
import { APP_ENV, SITE_URL } from "@/config";
import { AppEnv } from "@/types";
import type { MetadataRoute } from "next";

const robots = (): MetadataRoute.Robots => ({
rules: {
userAgent: "*",
allow: "/",
},
sitemap: `${SITE_URL}/sitemap.xml/`,
});
const robots = (): MetadataRoute.Robots => {
// Set the default rule
let rules: MetadataRoute.Robots["rules"] = { userAgent: "*" };

// Allow or disallow indexing based on app environment
if (APP_ENV === AppEnv.PROD) {
rules = { ...rules, allow: "/" };
} else {
rules = { ...rules, disallow: "/" };
}

return {
rules,
sitemap: `${SITE_URL}/sitemap.xml`,
};
};

export default robots;
4 changes: 4 additions & 0 deletions config/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import type { AppEnv } from "@/types";

const DOMAIN_NAME = "sgcarstrends.com";
const API_VERSION = "v1";

export const SITE_URL: string =
process.env.NEXT_PUBLIC_SITE_URL || `https://${DOMAIN_NAME}`;
export const SITE_TITLE = "SG Cars Trends";

export const APP_ENV = process.env.APP_ENV as AppEnv;

// Configure the API BASE URL
const DEFAULT_API_URL = `https://api.${DOMAIN_NAME}`;
const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || DEFAULT_API_URL;
Expand Down
1 change: 1 addition & 0 deletions sst.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default $config({
},
environment: {
SG_CARS_TRENDS_API_TOKEN: process.env.SG_CARS_TRENDS_API_TOKEN,
APP_ENV: $app.stage,
},
});
},
Expand Down
6 changes: 6 additions & 0 deletions types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,9 @@ export enum RevalidateTags {
}

export type Make = Car["make"];

export enum AppEnv {
DEV = "dev",
STAGING = "staging",
PROD = "prod",
}

0 comments on commit 5c3da19

Please sign in to comment.