Skip to content

Commit

Permalink
👷 Move preview to lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
pouretrebelle committed May 3, 2021
1 parent 39c80c5 commit 8c38cfc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/pages/api/preview/[sketch].ts → lambdas/preview.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import path from 'path'
import SimplexNoise from 'simplex-noise'
import { createCanvas } from 'canvas'

import { Design, Cut } from 'types'
import { makeRandomSeed } from 'lib/seeds'

import { settings, design, DesignNoiseSeeds, cut, CutNoiseSeeds } from '../../../../sketches/001'

interface Req {
query: {
Expand All @@ -26,7 +26,7 @@ const handler = async (req: Req, res: Res) => {
res.setHeader('content-type', 'image/png')

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

const canvasWidth = req.query.width ? parseInt(req.query.width) : 200
const queryDesignSeeds = req.query.designSeeds ? req.query.designSeeds.split(',') : []
Expand Down
22 changes: 18 additions & 4 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
{
"functions": {
"pages/api/preview/[sketch].ts": {
"includeFiles": "sketches/**"
"builds": [
{
"src": "next.config.js",
"use": "@vercel/next"
},
{
"src": "lambdas/**/*.ts",
"use": "@vercel/node",
"config": {
"includeFiles": ["sketches/**"]
}
}
}
],
"routes": [
{
"src": "/lambdas/(.+)",
"dest": "/lambdas/$1.ts"
}
]
}

0 comments on commit 8c38cfc

Please sign in to comment.