score:4
Accepted answer
import { NextApiRequest, NextApiResponse } from "next";
import nc from "next-connect";
const apiRoute = nc<NextApiRequest, NextApiResponse>({
onError(error, req, res) {
res.status(501).json({ error: `Sorry something Happened! ${error.message}` })
},
onNoMatch(req, res) {
res.status(405).json({ error: `Method '${req.method}' Not Allowed` })
},
})
apiRoute.post((req, res) => {
res.status(200).json({ data: 'success' })
})
Source: stackoverflow.com
Related Query
- TypeScript error: Property 'scrollIntoView' does not exist on type 'never'. TS2339
- Property 'click' does not exist on type 'never'. TS2339
- Property does not exist on type 'Readonly<{}> & Readonly<{ children?: ReactNode; }>'. TS2339
- How to set function props type for its child in Typescript? Property 'children' does not exist on type TS2339
- React typescript, Property 'propTypes' does not exist on type 'typeof TodoFilterItem'. TS2339
- Property does not exist on type 'JSX.IntrinsicElements'. TS2339
- Converting from React.js to React.tsx Property 'id' does not exist on type 'never'. TS2339
- Property 'menuInfo' does not exist on type 'ModeContextType | undefined'. TS2339
- Property 'customProperty' does not exist on type 'X[]'. Typescript React. TS2339
- TS2339 (TS) Property 'state' does not exist on type
- Property 'target' does not exist on type 'HTMLInputElement'. TypeScript React. TS2339
- Property 'userid' does not exist on type '{ }'. TS2339
- TS2339 Property myProperty does not exist on type SetStateAction<User>
- TS2339 Typescript error but unsure why... property does not exist on type
- Property 'xy' does not exist on type '{}'. TS2339
- TypeScript error - Property 'get' does not exist on type 'Reference'. TS2339
- Property 'value' does not exist on type 'Readonly<{}>'
- TypeScript error: Property 'X' does not exist on type 'Window'
- typescript + react/redux: property "yyy" does not exist on type 'intrinsicattributes & intrinsicclassattributes
- Typescript complains Property does not exist on type 'JSX.IntrinsicElements' when using React.createClass?
- error TS2339: Property 'for' does not exist on type 'HTMLProps<HTMLLabelElement>'
- TypeScript error after upgrading version 4 useParams () from react-router-dom Property 'sumParams' does not exist on type '{}'
- Property 'exact' does not exist on type
- Property 'toBeInTheDocument' does not exist on type 'Matchers<any>'
- Trigger click in Typescript - Property 'click' does not exist on type 'Element'
- Property does not exist on type 'DetailedHTMLProps, HTMLDivElement>' with React 16
- TS2339: Property 'tsReducer' does not exist on type 'DefaultRootState'
- Property ... does not exist on type 'IntrinsicAttributes & ...'
- Property 'XYZ' does not exist on type 'Readonly<{ children?: ReactNode; }> & Readonly<{}>'
- Property 'hot' does not exist on type 'NodeModule'.ts(2339)
More Query from same tag
- How to get percentage using "onUploadProgress" axios?
- Check if shortcut is present on homescreen as in normal mobile apps
- How to set state after data fetch complete in React
- Jest won't read any of my files for code coverage
- Passing Data between REACT sibling component
- Enabling a single button from an array of data enclosing in .map
- browserify cannot find module 'react'
- How to change a innerHtml of an div in React?
- How to fix the Argument of type 'Date[]' is not assignable to parameter of type '(prevState: undefined) in react
- React-Select losing focus for custom component "ValueContainer"
- react prop passing to child component only works with localhost backend
- Redirect and refresh page on form submission in React frontend
- How to make button content highlight animation?
- Ant Design: How can I disable border-bottom of a menu item on hover?
- Why list doesn't appear on the page? What are the errors in my React-Redux (Api) application? And how to fix them?
- React Native - Navigate after an async action
- Copy to clipboard is copying value with two newlines
- Child component is not rendering props
- React - Input not working when using onChange and onKeyDown
- React: Setting state to an es6 Map
- how to use recursive function call in react, which return some array?
- Serviceworker Chunk with CommonsChunkPlugin doesn't work, webpackJsonp is not defined
- React Nodejs - Custom @font-face in jsx for PDF generation
- Reactjs : Failed to load module script: WIth MIME type "application/octet-stream" for sharepoint webpart
- React - Can I verify if user pressed a key or not with on change event?
- How to update state inside array of objects on specific filed which is also array as on below code in REACT?
- Is it possible hide any input fields of a form during a cypress test?
- Deploying create-react-app project isn't uglifying my code
- REACT + FIREBASE : Manage user data with useContext
- Multiple instances of isFetching in redux reducer