Next.js Discord

Discord Forum

/api/version returning 404

Answered
Caspian Nightworth posted this in #help-forum
Open in Discord
I am using the recommended App Router and have in my app directory a folder called api and in it I have a file called version.ts.

The contents of that file is:
import { NextRequest, NextResponse } from 'next/server'; // Import from 'next/server'
import getConfig from 'next/config';

const { publicRuntimeConfig } = getConfig();

export async function GET(request: NextRequest) {  // Use 'GET'
  console.log('API Route Triggered:', publicRuntimeConfig.version);
  return NextResponse.json({ version: publicRuntimeConfig.version });
}


Trying to hit that route from http://localhost:3000/api/version I am returned with a 404. I cannot figure out why this is. I have restarted my application to see if it was just not being picked up, but that does not seem to be the case. Any help regarding this is greatly appreciated.
Answered by joulev
Yes
View full answer

6 Replies