nuxt 3 retrieve data that was sent from another server

I’m attempting to write a program to retrieve data in Nuxt3, with the data being sent from another server. Currently, my code is saved in pages/endpoint.ts. However, I am unable to access mydomain/endpoint.ts. If I need to change the file to endpoint.vue, how should I modify the code? Also, how can I verify the data sent by the other server?

import { IncomingRequest, ServerResponse } from 'nuxt'

export async function myEndpoint(req: IncomingRequest, res: ServerResponse) {
 if (req.method === 'POST') {
   // Retrieve the data from the request body
   const requestData = await req.json()

   // Log the incoming request data and timestamp
   console.log('Request received at:', new Date().toISOString())
   console.log('Request data:', requestData)

   // Process the data and send a response
   res.status(200).json({ message: 'Data received', data: requestData })
 } else {
   // Handle non-POST requests
   res.status(405).json({ error: 'Method not allowed' })
 }
}