Skip to content

How to use it in nextjs middleware? #20

@mnsrulz

Description

@mnsrulz

With very minimal configuration as shown below, it's running fine when running in local, but when it's getting deployed in netlify platform which uses edge runtime for middleware, it's erroring out.

import { log } from '@logtail/next'

export default auth((req) => {
       log.info(`${req.method} ${req.nextUrl.pathname}`, { path: req.nextUrl.pathname, method: req.method });
})

export const config = {
       matcher: ['/((?!api/auth|_next/static|_next/image|.*\\.png$|.*\\.ico$).*)']
};

Error

error  TypeError: Invalid URL: '/_logtail'
    at getSerialization (ext:deno_url/00_url.js:98:11)
    at new URL (ext:deno_url/00_url.js:405:27)
    at new Request (ext:deno_fetch/23_request.js:329:25)
    at ext:deno_fetch/26_fetch.js:319:27
    at new Promise (<anonymous>)
    at fetch (ext:deno_fetch/26_fetch.js:315:18)
    at file:///root/src/bootstrap/util/fetch.ts:110:14
    at e.<anonymous> (file:///root/.netlify/edge-functions/___netlify-edge-handler-src-middleware/server/src/middleware.js:417:66924)
    at file:///root/.netlify/edge-functions/___netlify-edge-handler-src-middleware/server/src/middleware.js:417:63725
    at Object.next (file:///root/.netlify/edge-functions/___netlify-edge-handler-src-middleware/server/src/middleware.js:417:63830)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions