Skip to content

Commit 130e77b

Browse files
committed
refactor: pure edge function
1 parent cdaeda5 commit 130e77b

File tree

4 files changed

+18
-25
lines changed

4 files changed

+18
-25
lines changed

pages/api/index.js renamed to api/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ const origins = process.env.ORIGINS?.split(',').map(n => n.trim())
1212

1313
const isProduction = NODE_ENV === 'production'
1414

15+
const baseUrl = ({ headers }) =>
16+
`${headers.get('x-forwarded-proto')}://${headers.get('x-forwarded-host')}`
17+
1518
const isAllowedDomain =
1619
isProduction && Array.isArray(origins)
1720
? origin => origins.includes(origin)
1821
: () => true
1922

2023
export default async request => {
21-
const url = request.nextUrl
24+
const url = new URL(request.url, baseUrl(request))
25+
2226
const origin = request.headers.get('origin')
2327

2428
if (request.method === 'OPTIONS') {

next.config.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@
2525
"proxy"
2626
],
2727
"dependencies": {
28-
"@microlink/mql": "~0.10.28",
29-
"next": "~13.0.0",
30-
"react": "~18.2.0",
31-
"react-dom": "~18.2.0"
28+
"@microlink/mql": "~0.10.28"
3229
},
3330
"devDependencies": {
3431
"@commitlint/cli": "latest",
@@ -51,11 +48,9 @@
5148
"src"
5249
],
5350
"scripts": {
54-
"build": "next build",
5551
"clean": "rm -rf node_modules",
5652
"contributors": "(git-authors-cli && finepack && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
57-
"dev": "TZ=UTC NODE_ENV=development DEBUG=microlink* next dev",
58-
"lint": "standard-markdown README.md && standard && next lint",
53+
"lint": "standard-markdown README.md && standard",
5954
"postrelease": "npm run release:tags && npm run release:github",
6055
"prerelease": "npm run update:check && npm run contributors",
6156
"pretest": "npm run lint",

vercel.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
{
2-
"builds": [
2+
"routes": [
33
{
4-
"src": "package.json",
5-
"use": "@vercel/next"
4+
"src": "/robots.txt",
5+
"status": 204
6+
},
7+
{
8+
"src": "/favicon.ico",
9+
"dest": "https://cdn.microlink.io/logo/trim.png"
10+
},
11+
{
12+
"src": "/(.*)",
13+
"dest": "/api/index.js"
614
}
715
]
816
}

0 commit comments

Comments
 (0)