Skip to content

Commit

Permalink
fix robots.txt + base URL (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
resir014 committed Oct 12, 2023
1 parent 521941f commit 485b631
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 32 deletions.
24 changes: 24 additions & 0 deletions lib/base-url.ts
@@ -0,0 +1,24 @@
export function getBaseUrl() {
if (typeof window !== 'undefined') {
// browser should use relative path
return '';
}

if (process.env.DEPLOY_PRIME_URL) {
// reference for netlify.com
return process.env.DEPLOY_PRIME_URL;
}

if (process.env.VERCEL_URL) {
// reference for vercel.com
return `https://${process.env.VERCEL_URL}`;
}

if (process.env.RENDER_INTERNAL_HOSTNAME) {
// reference for render.com
return `http://${process.env.RENDER_INTERNAL_HOSTNAME}:${process.env.PORT}`;
}

// assume localhost
return `http://localhost:${process.env.PORT ?? 3000}`;
}
8 changes: 7 additions & 1 deletion lib/data/site-metadata.ts
@@ -1,4 +1,5 @@
import siteMetadata from '~/_data/site-metadata.json';
import data from '~/_data/site-metadata.json';
import { getBaseUrl } from '../base-url';

export type SiteAuthor = {
readonly name: string;
Expand All @@ -18,4 +19,9 @@ export type SiteMetadata = {
readonly author: SiteAuthor;
};

const siteMetadata: SiteMetadata = {
...(data as unknown as SiteMetadata),
siteUrl: getBaseUrl() || data.siteUrl,
};

export default siteMetadata as unknown as SiteMetadata;
26 changes: 1 addition & 25 deletions lib/trpc.ts
@@ -1,31 +1,7 @@
import { httpBatchLink } from '@trpc/client';
import { createTRPCNext } from '@trpc/next';
import { AppRouter } from '~/server/routers/_app';

function getBaseUrl() {
if (typeof window !== 'undefined') {
// browser should use relative path
return '';
}

if (process.env.DEPLOY_PRIME_URL) {
// reference for netlify.com
return process.env.DEPLOY_PRIME_URL;
}

if (process.env.VERCEL_URL) {
// reference for vercel.com
return `https://${process.env.VERCEL_URL}`;
}

if (process.env.RENDER_INTERNAL_HOSTNAME) {
// reference for render.com
return `http://${process.env.RENDER_INTERNAL_HOSTNAME}:${process.env.PORT}`;
}

// assume localhost
return `http://localhost:${process.env.PORT ?? 3000}`;
}
import { getBaseUrl } from './base-url';

export const trpc = createTRPCNext<AppRouter>({
config() {
Expand Down
15 changes: 14 additions & 1 deletion next-sitemap.config.js
@@ -1,6 +1,19 @@
/** @type {import('next-sitemap').IConfig} */
module.exports = {
siteUrl: process.env.NEXT_PUBLIC_BASE_URL || 'https://resir014.xyz',
siteUrl:
process.env.NEXT_PUBLIC_BASE_URL || process.env.DEPLOY_PRIME_URL || 'https://resir014.xyz',
generateRobotsTxt: true,
robotsTxtOptions: {
policies: [
{
userAgent: '*',
allow: '/',
},
{
userAgent: 'GPTBot',
disallow: '/',
},
],
},
exclude: ['/etc/something-amazing'],
};
5 changes: 0 additions & 5 deletions public/robots.txt

This file was deleted.

0 comments on commit 485b631

Please sign in to comment.