Giter Club home page Giter Club logo

Comments (8)

smallpath avatar smallpath commented on July 20, 2024

应该是404返回Not Found, 然后你调用res.json()的时候没法把Not Found解析成JSON,于是报错说第一个字母N词法错误。

感觉要么是fetch请求格式有错, 要么是后端解析请求格式解析错了,稍后我做一下测试

from blog.

smallpath avatar smallpath commented on July 20, 2024

我尝试了一下,浏览器环境的fetch和node环境的fetch都没问题啊。
image

from blog.

smallpath avatar smallpath commented on July 20, 2024

你函数中headers里没有authorization字段应该会被服务器拒绝修改的,你是不是自己修改了permission函数?koa2中在回调里调用next函数就会出现你这种情况,应当将回调的形式改为co/generator或者async/await这样的假协程形式

另外可以贴一下浏览器network页面中patch请求的详情,确保发起的请求没有问题

from blog.

anli001024 avatar anli001024 commented on July 20, 2024

谢谢,看了你的分析之后,我找到问题出现所在了。
因为还没做到验证登录那块,所以我直接把permission函数里面的内容注释掉了,只写了个next(),就出现了以上的问题。
我的解决方法: return netxt();
这样就。。解决了!
是因为koa-router里面的中间件必须return一个值吗?

from blog.

smallpath avatar smallpath commented on July 20, 2024

koa2中的next()返回的是promise,估计koa中检查到非promise的返回值时就直接跳到默认的Error Handler中间件了

from blog.

anli001024 avatar anli001024 commented on July 20, 2024

原来是这样,谢谢你啦!
我还想问一下,如果前后台都写好了,准备上线自己的博客,因为服务器端的koa2只是一个简单的REST服务器,那么前后台的网页应该放哪?
还是直接修改koa2去render前后台的网页呢?

from blog.

smallpath avatar smallpath commented on July 20, 2024

看你是前后端分离还是传统的MVC咯,前后端分离的话构建出静态资源用nginx代理即可,传统MVC还需要nginx额外配置端口的信息。前者的nginx可以参考本博客admin的部署nginx模板,后者可以参考本博客front的部署nginx文档,都在readme里有写

from blog.

anli001024 avatar anli001024 commented on July 20, 2024

谢谢!

from blog.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.