forked from transitive-bullshit/nextjs-notion-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrobots.txt.tsx
45 lines (35 loc) · 948 Bytes
/
robots.txt.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import type { GetServerSideProps } from 'next'
import { host } from '@/lib/config'
export const getServerSideProps: GetServerSideProps = async ({ req, res }) => {
if (req.method !== 'GET') {
res.statusCode = 405
res.setHeader('Content-Type', 'application/json')
res.write(JSON.stringify({ error: 'method not allowed' }))
res.end()
return {
props: {}
}
}
// cache for up to one day
res.setHeader('Cache-Control', 'public, max-age=86400, immutable')
res.setHeader('Content-Type', 'text/plain')
// only allow the site to be crawlable on the production deployment
if (process.env.VERCEL_ENV === 'production') {
res.write(`User-agent: *
Allow: /
Disallow: /api/get-tweet-ast/*
Disallow: /api/search-notion
Sitemap: ${host}/sitemap.xml
`)
} else {
res.write(`User-agent: *
Disallow: /
Sitemap: ${host}/sitemap.xml
`)
}
res.end()
return {
props: {}
}
}
export default () => null