Can you update the `runtime` property to `segment` in the export config?

I'm currently working on setting up an upload API route within my application.

/admin/upload

However, when I attempt to console.log(req.file), it returns as undefined.

This seems to be related to the following configuration:

export const config = {
    api: {
        bodyParser: false,
    }
}

It appears that this setup is not compatible with the app router, and I'm struggling to find alternative solutions.

import { createEdgeRouter } from "next-connect";
import { NextResponse } from "next/server";
import multer from "multer";

export const config = {
    api: {
        bodyParser: false,
    }
}

const router = createEdgeRouter();

const upload = multer({
    storage: multer.diskStorage({
        destination: './public/uploads',
        filename: (req, file, cb) => cb(null, file.originalname),
    }),
});

const file = upload.single('file');
router
    .use(file)
    .post((req) => {
        // console.log(req.pageType);
        console.log(req.pageType);
        return NextResponse.json({ 'message': 'Hi mom' })
    });

export async function POST(req, ctx) {
    return NextResponse.json("Hi")
}

This is the code snippet for my backend. I've consulted the documentation provided at the specified page, but haven't found any useful insights. Do you have any suggestions on how to troubleshoot this issue?

Please keep in mind that I am utilizing the app router instead of the pages router.

Answer №1

Perhaps this could offer a solution. I encountered a similar issue when integrating it into my Stripe webhook endpoint, transitioning from pages/ to /app.

Upon discovering the GitHub thread, I found more valuable insights than what was provided in the error message link.

Answer №2

Add it to the main directory of the project (or inside the /src folder if applicable)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error: JSONP Label Validation Failed

My JSON URL is: The above URL returns the following JSON: { token: "2cd3e37b-5d61-4070-96d5-3dfce0d0acd9%a00a5e34-b017-4899-8171-299781c48c72" } Edit: Changed it to {"token": "2cd3e37b-5d61-4070-96d5-3dfce0d0acd9%a00a5e34-b017-4899-8171-299781c48c72"} ...

What is the best way to configure the default entry point for a package.json file in a React

I'm having trouble with the default export in my package.json file. when I try to import: import { Component } from 'packagename/'; // size 22kb or import { Component } from 'packagename/dist' // size 22kb; but import { Component ...

Limiting the draggable element within a compact container using jquery UI

I've been attempting to drag an <img> within a fixed-width and fixed-height container. Despite researching on Stack Overflow and finding this solution, it doesn't seem to work for my specific case. If you check out this fiddle I created, y ...

When executing JavaScript code, the file remains unchanged and does not alter the URL

I want my form to check a SQL database upon submission and execute a JavaScript file that captures the data into a constant. However, instead of running the JS script on the page as desired, it redirects to a new URL. Is there a way to ensure that the JS ...

$.ajax causing a JSON input string malfunction

My web API requires the following JSON format for input: [{ "atrSpaUserId": "47fe8af8-0435-401e-9ac2-1586c8d169fe", "atrSpaClassLegendId": "00D18EECC47E7DF44200011302", "atrSpaCityDistrictId": "144d0d78-c8eb-48a7-9afb-fceddd55622c"}, { "atrSpaUserId": "47 ...

Is there a way to configure MaterialUI XGrid filters to target and filter by the renderCell parameters instead of the backend data source?

While utilizing MaterialUI XGrid to showcase rows of information, I am facing an issue with filtering. Currently, filtering can only be done based on the backend row values rather than what is displayed in the cell. For instance, consider a column named U ...

What is the best way to link PostgreSQL with a React frontend using restify?

Login.js This is a Reactjs login page that requires moving to the next page after successful authentication. The database being used is postgreSQL with a table named 'user' for storing usernames and passwords. The development requirements inc ...

Encountering the error "Text content does not match" when using Next.js with next-i18next

I have followed the instructions for setting up next-i18next, but I am encountering an error that says "Text content did not match. Server: Testing ZH HANT Client: Testing EN" - even though only English text is displayed on the frontend. I seem to have ove ...

Metronome in TypeScript

I am currently working on developing a metronome using Typescript within the Angular 2 framework. Many thanks to @Nitzan-Tomer for assisting me with the foundational concepts, as discussed in this Stack Overflow post: Typescript Loop with Delay. My curren ...

What is the best method for playing raw audio wav files directly in a web browser?

I'm currently attempting to play wav raw data in the browser that is being transmitted from a Node.js server via socket.io. The main goal is to play the receiving data as quickly as possible without waiting for all the data to be received. I initially ...

Can you explain the purpose of the statement `var MyConstructor = function MyConstructor()`?

Can you explain the distinction between these two code snippets: var NodestrapGenerator = module.exports = function NodestrapGenerator() { yeoman.generators.Base.apply(this, arguments); // more code here }; and: var NodestrapGenerator = module.expor ...

Alert: Github Dependabot has flagged Babel as vulnerable to arbitrary code execution when compiling meticulously designed malicious code

My Github Repository's Security section is flagging this issue as Critical for both my Frontend and Backend code. I'm having trouble grasping the nature of this alert. Can someone explain what flaw it represents? After updating my dependencies, ...

npm global installation error: extraneous package

Locally, I have noticed this issue with node modules but not globally. What is the root cause of this problem and what steps can be taken to prune it? https://i.stack.imgur.com/d4G1y.png ...

What is the process for adding elements to the parent elements that have been selected using getElementsByClassName?

Here is the JSP code snippet I'm working with: <% while(resultSet1.next()){ out.println("<p class='comm'>"); out.println(resultSet1.getString("answer_content")); ...

Javascript function to deselect all items

One of my functions is designed to reset all checkbox values and then trigger an AJAX request. However, there are instances when the function initiates before the checkboxes have been unchecked. function clear() { $("#a").prop("checked", false); $("#b ...

Troubleshooting: Heroku Node Version Update Issue

Looking to update the node version of my app deployed on Heroku. Currently, it is running version 0.10.40 on the Heroku app. To switch to the desired version, I made changes to the package.json file as follows: { "name": "myapp", "private": true, " ...

Displaying various Ajax html responses

The function $('.my-button').click(function(e) is designed to display the output of the MySQL query in display.php, presented in HTML format. While it functions correctly, since each button is looped for every post, the script only works for the ...

Why is there a delay in processing queries and requests in the MEAN Stack?

Recently, I've been diving into Node.js and experimenting with building a web app using the MEAN stack. One particular issue I encountered involved sending an array of strings (e.g., ["one", "two", "three"]) to the server side. In response, I attempt ...

Fetching all data from a SQLite database in a Listview using React Native

I have been utilizing the library found at https://github.com/andpor/react-native-sqlite-storage in my react native project. To retrieve a single row from the database, I use the following code: db.transaction((tx) => { tx.executeSql('SEL ...

Canvas 'toDataURL' Execution Error Occurs with Angular Dynamic Routing

For my Web application, I am using AngularJS on top of Node/Express. One of the routes in my application has an HTML5 canvas which I convert to an image. When I navigate to that route directly with this code, there are no problems with converting the canva ...