diff --git a/.vercel.json b/.vercel.json new file mode 100644 index 0000000..8a54a77 --- /dev/null +++ b/.vercel.json @@ -0,0 +1,7 @@ +{ + "functions": { + "api/search.ts": { + "includeFiles": "cache/**" + } + } +} diff --git a/pages/api/messages.ts b/api/messages.ts similarity index 100% rename from pages/api/messages.ts rename to api/messages.ts diff --git a/pages/api/search.ts b/api/search.ts similarity index 86% rename from pages/api/search.ts rename to api/search.ts index 960b14c..da021b2 100644 --- a/pages/api/search.ts +++ b/api/search.ts @@ -1,6 +1,6 @@ import { NextApiRequest, NextApiResponse } from 'next'; -import Search from '../../utils/libs/search'; +import Search from '../utils/libs/search'; export default (req: NextApiRequest, res: NextApiResponse) => { const term = req.query.term as string; diff --git a/public/data.json b/cache/data.json similarity index 100% rename from public/data.json rename to cache/data.json diff --git a/utils/libs/cache.ts b/utils/libs/cache.ts index 9ed6a9d..ec834e6 100644 --- a/utils/libs/cache.ts +++ b/utils/libs/cache.ts @@ -3,7 +3,7 @@ import path from 'path'; import { getArticle, getArticlesList } from '../datasource'; -const CACHE_PATH = 'public'; +const CACHE_PATH = 'cache'; const CACHE_FILE = 'data.json'; export interface CacheEntry { @@ -35,7 +35,7 @@ export function updateArticlesCache() { } export function getArticlesCache(): CacheEntry[] { - const rawData = fs.readFileSync(path.join(CACHE_PATH, CACHE_FILE)); + const rawData = fs.readFileSync(path.join(CACHE_PATH, CACHE_FILE), 'utf8'); if (!rawData) { return [];