Skip to content

Commit

Permalink
🐛 Copy sketches files into src folder
Browse files Browse the repository at this point in the history
It's impossible to read files in serverless functions from outside the src folder. I've tried a lot of things, including various import workarounds and converting the api route into a separate lambda. This is the most elegant solution for now.

See:
- vercel/next.js#8251
- vercel/next.js#8251 (comment)
- vercel/vercel#3083 (comment)
  • Loading branch information
pouretrebelle committed May 7, 2021
1 parent aa7de56 commit 398c7ab
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# production
/build
/public/sketches
/src/.temp

# misc
.DS_Store
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"start": "next start",
"lint": "eslint . --ext .ts,.tsx",
"type-check": "tsc --noEmit",
"vercel-build": "yum install libuuid-devel libmount-devel zlib-devel && cp /lib64/{libuuid,libmount,libblkid}.so.1 node_modules/canvas/build/Release/ && npm run build"
"vercel-build": "yum install libuuid-devel libmount-devel zlib-devel && cp /lib64/{libuuid,libmount,libblkid}.so.1 node_modules/canvas/build/Release/ && mkdir -p src/.temp/sketches && npm run sync:sketches && npm run build",
"sync:sketches": "cp -r sketches/ src/.temp"
},
"engines": {
"node": "12.x"
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/preview/[sketch].ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Res = NodeJS.WritableStream & {
const handler = async (req: Req, res: Res) => {
res.setHeader('content-type', 'image/png')

const { settings, design, DesignNoiseSeeds, cut, CutNoiseSeeds } = await import(`../../../../sketches/${req.query.sketch || '001'}/index.ts`)
const { settings, design, DesignNoiseSeeds, cut, CutNoiseSeeds } = await import(`.temp/sketches/${req.query.sketch || '001'}/index.ts`)

const canvasWidth = req.query.width ? parseInt(req.query.width) : 200
const queryDesignSeeds = req.query.designSeeds ? req.query.designSeeds.split(',') : []
Expand Down

0 comments on commit 398c7ab

Please sign in to comment.