Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nextjs _middleware not console.log

I have followed the guideline to insert a middleware into one of my pages.

in the sub directory /appstore I have created _middleware.js inside that I am trying to just get something to console log so I know the file is working.

The end result will be that I want to detect if they are android or iOS and redirect them to the correct store.

import { NextFetchEvent, NextRequest } from 'next/server'

export function middleware() {
  console.log('Hello, world!')
}   

However when I visit the page I get in console.log = NULL so clearly something is not quite right?

like image 876
Russell Harrower Avatar asked Sep 07 '25 13:09

Russell Harrower


1 Answers

Since the middleware works server side you can see the console.log() results only on the terminal where you execute the npm run dev or npm run start command.

It will display nothing on the client (browser console).

Just for reference, adding the Documentation for the next/server server-only helpers.

like image 63
TheodorosPloumis Avatar answered Sep 10 '25 07:09

TheodorosPloumis