我正在尝试在我的 NextJS 应用程序中点击创建一个基本的帖子到 MongoDB 数据库。我得到的问题是TypeError: resolver is not a function。我知道这可能是一个同步问题,但对于我的生活,我不知道在哪里。
使用的堆栈:NextJS、Axios、Mongoose。
调用 axios 的组件代码片段:
我知道状态正在更新,所以我只放置处理请求的片段
handleSubmit = async (e: any) => {
e.preventDefault();
await axios
.post('/api/roomSession', {
roomName: this.state.roomName,
teamName: this.state.teamName
})
.then((response: any) => console.log('axios call reached', response))
.catch((error: any) => console.log('---- error! ----', error));
};
[...]
<button onClick={this.handleSubmit}>Create</button>
[...]
Run Code Online (Sandbox Code Playgroud)
NextJS API 文件:
import { newSession } from '../../packages/backend/mongo/connection';
const apiNewSession = async (roomName, teamName) => {
await newSession(teamName, roomName);
};
export default apiNewSession();
Run Code Online (Sandbox Code Playgroud)
猫鼬文件:
const mongoose …Run Code Online (Sandbox Code Playgroud)