Merge pull request #405 from spencerwooo/edge-caching
This commit is contained in:
commit
601ae3ce8b
5 changed files with 17 additions and 1 deletions
|
@ -9,7 +9,7 @@ const HomeCrumb = () => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Link href="/">
|
<Link href="/">
|
||||||
<a>
|
<a className="flex items-center">
|
||||||
<FontAwesomeIcon className="h-3 w-3" icon={['far', 'flag']} />
|
<FontAwesomeIcon className="h-3 w-3" icon={['far', 'flag']} />
|
||||||
<span className="ml-2 font-medium">{t('Home')}</span>
|
<span className="ml-2 font-medium">{t('Home')}</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -131,6 +131,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
// If method is GET, then the API is a normal request to the OneDrive API for files or folders
|
// If method is GET, then the API is a normal request to the OneDrive API for files or folders
|
||||||
const { path = '/', raw = false, next = '' } = req.query
|
const { path = '/', raw = false, next = '' } = req.query
|
||||||
|
|
||||||
|
// Set edge function caching for faster load times, check docs:
|
||||||
|
// https://vercel.com/docs/concepts/functions/edge-caching
|
||||||
|
res.setHeader('Cache-Control', 'max-age=0, s-maxage=600, stale-while-revalidate')
|
||||||
|
|
||||||
// Sometimes the path parameter is defaulted to '[...path]' which we need to handle
|
// Sometimes the path parameter is defaulted to '[...path]' which we need to handle
|
||||||
if (path === '[...path]') {
|
if (path === '[...path]') {
|
||||||
res.status(400).json({ error: 'No path specified.' })
|
res.status(400).json({ error: 'No path specified.' })
|
||||||
|
|
|
@ -11,6 +11,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
// Get item details (specifically, its path) by its unique ID in OneDrive
|
// Get item details (specifically, its path) by its unique ID in OneDrive
|
||||||
const { id = '' } = req.query
|
const { id = '' } = req.query
|
||||||
|
|
||||||
|
// Set edge function caching for faster load times, check docs:
|
||||||
|
// https://vercel.com/docs/concepts/functions/edge-caching
|
||||||
|
res.setHeader('Cache-Control', 'max-age=0, s-maxage=600, stale-while-revalidate')
|
||||||
|
|
||||||
if (typeof id === 'string') {
|
if (typeof id === 'string') {
|
||||||
const itemApi = `${apiConfig.driveApi}/items/${id}`
|
const itemApi = `${apiConfig.driveApi}/items/${id}`
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
// Query parameter from request
|
// Query parameter from request
|
||||||
const { q: searchQuery = '' } = req.query
|
const { q: searchQuery = '' } = req.query
|
||||||
|
|
||||||
|
// Set edge function caching for faster load times, check docs:
|
||||||
|
// https://vercel.com/docs/concepts/functions/edge-caching
|
||||||
|
res.setHeader('Cache-Control', 'max-age=0, s-maxage=600, stale-while-revalidate')
|
||||||
|
|
||||||
if (typeof searchQuery === 'string') {
|
if (typeof searchQuery === 'string') {
|
||||||
// Construct Microsoft Graph Search API URL, and perform search only under the base directory
|
// Construct Microsoft Graph Search API URL, and perform search only under the base directory
|
||||||
const searchRootPath = encodePath('/')
|
const searchRootPath = encodePath('/')
|
||||||
|
|
|
@ -15,6 +15,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
// Get item thumbnails by its path since we will later check if it is protected
|
// Get item thumbnails by its path since we will later check if it is protected
|
||||||
const { path = '', size = 'medium' } = req.query
|
const { path = '', size = 'medium' } = req.query
|
||||||
|
|
||||||
|
// Set edge function caching for faster load times, check docs:
|
||||||
|
// https://vercel.com/docs/concepts/functions/edge-caching
|
||||||
|
res.setHeader('Cache-Control', 'max-age=0, s-maxage=600, stale-while-revalidate')
|
||||||
|
|
||||||
// Check whether the size is valid - must be one of 'large', 'medium', or 'small'
|
// Check whether the size is valid - must be one of 'large', 'medium', or 'small'
|
||||||
if (size !== 'large' && size !== 'medium' && size !== 'small') {
|
if (size !== 'large' && size !== 'medium' && size !== 'small') {
|
||||||
res.status(400).json({ error: 'Invalid size' })
|
res.status(400).json({ error: 'Invalid size' })
|
||||||
|
|
Loading…
Reference in a new issue