Skip to content

Commit

Permalink
Merge pull request #12 from styxlab/fix-runtime-502
Browse files Browse the repository at this point in the history
Fix runtime 502
  • Loading branch information
styxlab authored Dec 29, 2020
2 parents f090f4c + 5243e12 commit e9ceae2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
12 changes: 10 additions & 2 deletions lib/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ import path from 'path'
import { fileCache } from '@appConfig'

const cacheRoot = path.join(process.cwd(), '.cache')
if (!fs.existsSync(cacheRoot)) {
fs.mkdirSync(cacheRoot)

const makeDirectory = (path: string) => {
if (fs.existsSync(path)) return true
try {
fs.mkdirSync(path)
} catch {
return false
}
return true
}

export function getCache<T>(key: string | null): T | null {
Expand All @@ -21,6 +28,7 @@ export function getCache<T>(key: string | null): T | null {

export function setCache(key: string | null, object: unknown): void {
if (!fileCache || !key) return
if (!makeDirectory(cacheRoot)) return

const filePath = path.join(cacheRoot, `${key}.txt`)
fs.writeFileSync(filePath, JSON.stringify(object as JSON))
Expand Down
3 changes: 0 additions & 3 deletions lib/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ export const imageDimensionsFromFile = async (file: string, noCache?: boolean) =
*/

const imageRoot = join(process.cwd(), 'public/images')
if (!existsSync(imageRoot)) {
mkdirSync(imageRoot)
}

export const normalizedImageUrl = async (url: string) => {
const localhostRegExp = /^http:\/\/\w+(\.\w+)*(:[0-9]+)?\/?(\/.*)*\/(.*)$/
Expand Down
1 change: 1 addition & 0 deletions pages/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export const getStaticProps: GetStaticProps = async ({ params }) => {
if (dimensions) contactPage.featureImage = { url, dimensions }
}
}

if (!post && !page && !isContactPage) {
return {
notFound: true,
Expand Down

1 comment on commit e9ceae2

@vercel
Copy link

@vercel vercel bot commented on e9ceae2 Dec 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.