mirror of
https://github.com/d0zingcat/nextjs-notion-starter-kit.git
synced 2026-05-13 23:16:47 +00:00
feat: bug fixes and update core deps
This commit is contained in:
25
pages/api/get-tweet-ast/[tweetId].ts
Normal file
25
pages/api/get-tweet-ast/[tweetId].ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { fetchTweetAst } from 'static-tweets'
|
||||
|
||||
export default async (
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse
|
||||
): Promise<void> => {
|
||||
if (req.method !== 'GET') {
|
||||
return res.status(405).send({ error: 'method not allowed' })
|
||||
}
|
||||
|
||||
const tweetId = req.query.tweetId as string
|
||||
|
||||
if (!tweetId) {
|
||||
return res
|
||||
.status(400)
|
||||
.send({ error: 'missing required parameter "tweetId"' })
|
||||
}
|
||||
|
||||
console.log('getTweetAst', tweetId)
|
||||
const tweetAst = await fetchTweetAst(tweetId)
|
||||
console.log('tweetAst', tweetId, tweetAst)
|
||||
|
||||
res.status(200).json(tweetAst)
|
||||
}
|
||||
23
pages/api/robots.txt.ts
Normal file
23
pages/api/robots.txt.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
|
||||
import { host } from '../../lib/config'
|
||||
|
||||
export default async (
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse
|
||||
): Promise<void> => {
|
||||
if (req.method !== 'GET') {
|
||||
return res.status(405).send({ error: 'method not allowed' })
|
||||
}
|
||||
|
||||
// cache robots.txt for up to 60 seconds
|
||||
res.setHeader(
|
||||
'Cache-Control',
|
||||
'public, s-maxage=60, max-age=60, stale-while-revalidate=60'
|
||||
)
|
||||
res.setHeader('Content-Type', 'text/plain')
|
||||
res.write(`User-agent: *
|
||||
Sitemap: ${host}/api/sitemap.xml
|
||||
`)
|
||||
res.end()
|
||||
}
|
||||
21
pages/api/search-notion.ts
Normal file
21
pages/api/search-notion.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
|
||||
import * as types from '../../lib/types'
|
||||
import { search } from '../../lib/notion'
|
||||
|
||||
export default async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
if (req.method !== 'POST') {
|
||||
return res.status(405).send({ error: 'method not allowed' })
|
||||
}
|
||||
|
||||
const searchParams: types.SearchParams = req.body
|
||||
|
||||
console.log('lambda search-notion', searchParams)
|
||||
const results = await search(searchParams)
|
||||
|
||||
res.setHeader(
|
||||
'Cache-Control',
|
||||
'public, s-maxage=60, max-age=60, stale-while-revalidate=60'
|
||||
)
|
||||
res.status(200).json(results)
|
||||
}
|
||||
50
pages/api/sitemap.xml.ts
Normal file
50
pages/api/sitemap.xml.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
|
||||
import { SiteMap } from '../../lib/types'
|
||||
import { host } from '../../lib/config'
|
||||
import { getSiteMaps } from '../../lib/get-site-maps'
|
||||
|
||||
export default async (
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse
|
||||
): Promise<void> => {
|
||||
if (req.method !== 'GET') {
|
||||
return res.status(405).send({ error: 'method not allowed' })
|
||||
}
|
||||
|
||||
const siteMaps = await getSiteMaps()
|
||||
|
||||
// cache sitemap for up to one hour
|
||||
res.setHeader(
|
||||
'Cache-Control',
|
||||
'public, s-maxage=3600, max-age=3600, stale-while-revalidate=3600'
|
||||
)
|
||||
res.setHeader('Content-Type', 'text/xml')
|
||||
res.write(createSitemap(siteMaps[0]))
|
||||
res.end()
|
||||
}
|
||||
|
||||
const createSitemap = (siteMap: SiteMap) =>
|
||||
`
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
<url>
|
||||
<loc>${host}</loc>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>${host}/</loc>
|
||||
</url>
|
||||
|
||||
${Object.keys(siteMap.canonicalPageMap)
|
||||
.map((canonicalPagePath) =>
|
||||
`
|
||||
<url>
|
||||
<loc>${host}/${canonicalPagePath}</loc>
|
||||
</url>
|
||||
`.trim()
|
||||
)
|
||||
.join('')}
|
||||
</urlset>
|
||||
</xml>
|
||||
`
|
||||
Reference in New Issue
Block a user