From 292dfc90571177a529d34bc1ce01abbe83b4b86f Mon Sep 17 00:00:00 2001 From: Mike Fix Date: Wed, 17 Nov 2021 18:54:38 -0800 Subject: [PATCH] Try optional catch all routing (#1277) * try optional catch all routing * use rewrites * move rewrite to vercel.json Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com> --- api/image/{[id].js => [...id].js} | 8 ++++++-- api/image/index.js | 1 - vercel.json | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) rename api/image/{[id].js => [...id].js} (94%) delete mode 100644 api/image/index.js diff --git a/api/image/[id].js b/api/image/[...id].js similarity index 94% rename from api/image/[id].js rename to api/image/[...id].js index 268a1d4..0c0c9f9 100755 --- a/api/image/[id].js +++ b/api/image/[...id].js @@ -43,8 +43,12 @@ module.exports = async (req, res) => { }) try { - const { state, id, ...params } = - req.method === 'GET' ? req.query : await json(req, { limit: '6mb' }) + const { + state, + id: _id, + ...params + } = req.method === 'GET' ? req.query : await json(req, { limit: '6mb' }) + const id = _id && _id !== 'index' ? _id : undefined const page = await browser.newPage() diff --git a/api/image/index.js b/api/image/index.js deleted file mode 100644 index d4f7b6a..0000000 --- a/api/image/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('./[id]') diff --git a/vercel.json b/vercel.json index 6ba3d98..646f08e 100644 --- a/vercel.json +++ b/vercel.json @@ -5,5 +5,6 @@ "github": { "autoAlias": false, "silent": true - } + }, + "rewrites": [{ "source": "/api/image", "destination": "/api/image/index" }] } \ No newline at end of file