diff --git a/pages/api/index.js b/api/index.js similarity index 87% rename from pages/api/index.js rename to api/index.js index ea1e918..e86df2d 100644 --- a/pages/api/index.js +++ b/api/index.js @@ -12,13 +12,17 @@ const origins = process.env.ORIGINS?.split(',').map(n => n.trim()) const isProduction = NODE_ENV === 'production' +const baseUrl = ({ headers }) => + `${headers.get('x-forwarded-proto')}://${headers.get('x-forwarded-host')}` + const isAllowedDomain = isProduction && Array.isArray(origins) ? origin => origins.includes(origin) : () => true export default async request => { - const url = request.nextUrl + const url = new URL(request.url, baseUrl(request)) + const origin = request.headers.get('origin') if (request.method === 'OPTIONS') { diff --git a/next.config.js b/next.config.js deleted file mode 100644 index 98fbafa..0000000 --- a/next.config.js +++ /dev/null @@ -1,14 +0,0 @@ -module.exports = { - async rewrites () { - return [ - { - source: '/favicon.ico', - destination: 'https://cdn.microlink.io/logo/trim.png' - }, - { - source: '/:path*', - destination: '/api/:path*' - } - ] - } -} diff --git a/package.json b/package.json index ca5a33d..7bc84a3 100644 --- a/package.json +++ b/package.json @@ -25,10 +25,7 @@ "proxy" ], "dependencies": { - "@microlink/mql": "~0.10.28", - "next": "~13.0.0", - "react": "~18.2.0", - "react-dom": "~18.2.0" + "@microlink/mql": "~0.10.28" }, "devDependencies": { "@commitlint/cli": "latest", @@ -51,11 +48,9 @@ "src" ], "scripts": { - "build": "next build", "clean": "rm -rf node_modules", "contributors": "(git-authors-cli && finepack && git add package.json && git commit -m 'build: contributors' --no-verify) || true", - "dev": "TZ=UTC NODE_ENV=development DEBUG=microlink* next dev", - "lint": "standard-markdown README.md && standard && next lint", + "lint": "standard-markdown README.md && standard", "postrelease": "npm run release:tags && npm run release:github", "prerelease": "npm run update:check && npm run contributors", "pretest": "npm run lint", diff --git a/vercel.json b/vercel.json index 9d23797..61021f9 100644 --- a/vercel.json +++ b/vercel.json @@ -1,8 +1,16 @@ { - "builds": [ + "routes": [ { - "src": "package.json", - "use": "@vercel/next" + "src": "/robots.txt", + "status": 204 + }, + { + "src": "/favicon.ico", + "dest": "https://cdn.microlink.io/logo/trim.png" + }, + { + "src": "/(.*)", + "dest": "/api/index.js" } ] }