Tag: koa

问题与护照叽叽喳喳战略

我有一个应用程序,我已经与Koa节点写了。 我正在使用护照进行身份validation,Twitter的oauth护照叽叽喳喳,和koa护照,使其与科阿工作。 直到最近,与login的一切都完美。 我开始吸引朋友们对github的一些兴趣,当我试图让新人们关注这个项目时,人们开始有问题无法login并得到这个消息: 哇! 这个页面没有请求令牌。 这是我们需要使用您的Twitter帐户的应用程序的特殊关键。 请回到发送给您的网站或应用程序,然后重试。 这可能只是一个错误。 奇怪的是,我的生产服务器是最新的存储库,并在那里login工作得很好。 我的两台本地机器上的login也同样适用。 当我完全从我的笔记本电脑中删除项目,然后再次将其删除,它也开始有这个问题。 这是我的auth.js中的代码 var passport = require('koa-passport'); var settings = require('./settings'); var Promise = require('../plugins/base/common').Promise; var config = require('../config.json'); passport.serializeUser(function(user, done) { done(null, user) }) passport.deserializeUser(function(user, done) { done(null, user) }) if (process.env.NODE_ENV == "production"){ var domainStr = "http://productionurl.com"; }else{ var domainStr = "http://127.0.0.1:3000"; } […]

提供静态图像Koa.js

例如,在我的一个terminal中,我以JSON的forms返回一个值: { "image":"http//devservername/assets/someimage.jpg" } 我试图找出如何静态地通过Koa.js服务,不知道如果这将是一个路线或什么…

通过Ajax请求发送后无法parsingJSON

客户端 在将JSON.stringy应用到对象之后,将它像这样发送到节点服务器(作为POST请求): {"id":"topFolder","parentPath":null,"name":"newProject","is":"root","children":[]} 我通过Polymer的iron-ajax元素在客户端发送请求: <iron-ajax id="ajaxSave" method="POST" url="/save" handle-as="json" on-response="doit" </iron-ajax> 它是用这个函数发送的: save: function() { var v = JSON.stringify(this.data); this.$.ajaxSave.body = v; this.$.ajaxSave.generateRequest(); } 服务器端 然后我尝试在Koa-server上使用JSON.parse请求的正文(使用Koa-Body作为正文parsing器): router.post('/save', body, function*(){ let data = JSON.parse(this.request.body); this.body = "all ok"; }) 我得到一个SyntaxError: Unexpected token o和原始的机构看起来像这样: { '{"id":"topFolder","parentPath":null,"name":"new Project","is":"root","children":': [ '' ] } 为什么收到的身体看起来不同,我该如何解决? 编辑:这是一个完整的curl命令的请求: curl'http :// localhost:3000 / […]

构成koaasynchronous函数中间件的错误

我正在使用koa-compose将指南中build议的中间件放在一起。 我inputkoa-compose作为kompose 。 我有以下代码: const home = async function home (ctx,next) { if(ctx.path === '/') { ctx.body = 'Hello World!' } else { await next() } } const random = async function random (ctx,next) { console.log(ctx) if(ctx.path === '/random') { console.log('Inside random function') ctx.body = Math.floor(Math.random() * 10) } else { await next() } } […]

如何使用koajs发送一个http响应

我试图通过Facebookvalidationwebhook。 所以Facebook的点击我的urlmy-url/facebook/receive我的路由在nodejs我会做res.send(req.query['hub.challenge']); 发送一个http响应。 我正在使用KoaJS。 据我所知,Koajs将请求和响应对象合并到ctx但是在通过文档阅读时,我找不到任何沿着ctx.send或类似的命令发送一个http响应。 任何人都可以给我一些方向或链接。 谢谢。

以KOA-NEO4J或BOLT的forms传递一组属性和节点作为POST语句

我正在构build一个连接到NEO4J实例的REST API。 我使用koa-neo4j库作为基础( https://github.com/assister-ai/koa-neo4j-starter-kit )。 我是所有这些技术的初学者,但由于这个论坛的一些帮助,我有基本的function工作。 例如,下面的代码允许我创build一个标签为“metric”的新节点,并设置名称和dateAdded属性。 url: /metric?metricName=Test&dateAdded=2/21/2017 index.js app.defineAPI({ method: 'POST', route: '/api/v1/imm/metric', cypherQueryFile: './src/api/v1/imm/metric/createMetric.cyp' }); createMetric.cyp” CREATE (n:metric { name: $metricName, dateAdded: $dateAdded }) return ID(n) as id 但是,我正在努力想知道如何处理更复杂的例子。 如果事先不知道在创build新节点时要添加多less属性,或者想要在单个后置语句中创build多个节点,我该如何处理情况。 理想情况下,我希望能够传递类似JSON的东西作为POST的一部分,它将包含我想要创build的所有节点,标签和属性。 是这样的可能吗? 我尝试使用下面的Cypher查询并在POST正文中传递JSONstring,但它不起作用。 UNWIND $props AS properties CREATE (n:metric) SET n = properties RETURN n 我可以更好地切换到Neo4j Rest API,而不是使用BOLT协议和KOA-NEO4J框架。 从我的研究中,我认为最好使用BOLT,但是我希望Rest API作为我的前后端之间的中间层,所以如果长远来说更容易,我愿意改变。 谢谢您的帮助!

KOA中的POST请求未定义请求主体

我是nodejs的初学者。 我正在尝试创build一个使用koa框架来处理HTTP请求的HTTP服务器。 以下是我的服务器的代码。 app.use(function * (next){ var ctx = this; var resource = url.parse(ctx.request.url, true, true).pathname; switch(resource) { case '/': resource = config.app.root + '/dist/index.html'; ctx.type = mime.lookup(resource); ctx.body = fs.readFileSync(resource, 'utf-8'); ctx.response.set('Access-Control-Allow-Origin', '*'); break; case '/fudge/contact': console.log('============================'); console.log(ctx.request); // no body console.log('============================'); console.log(ctx.req); // no body console.log('============================'); console.log(ctx.request.body) // is undefined break; default: resource […]

Mongoose模式方法是“不是一个函数”

我的模型看起来像这样,但是当我尝试使用verifyPassword ,它说TypeError: user.verifyPassword is not a function const User = new mongoose.Schema({ name: { type: String, required: true }, password: { type: String, required: true }, avatar: String, token: String, role: String, permissions: Array, email: { type: String, unique: true, required: true }, joined: { type: Number, default: ( new Date() * 1 ) } […]

如何与koa2运行简单的应用程序?

问题 我试图运行简单的http服务器使用koa2 ,但运行它有问题。 它使用es6 ,预计在未来的node.js版本中工作,我想知道如何可以与node v6.1.0运行它? 码 import Koa from 'koa'; const app = new Koa(); // Setup handler. app.use(async ctx => { ctx.body = "Hello World!"; }); // Start server. app.listen(3000); 产量 $ node –version v6.1.0 $ node –harmony index.js C:\Users\gevor\WebstormProjects\untitled1\index.js:1 (function (exports, require, module, __filename, __dirname) { import Koa from 'koa'; ^^^^^^ SyntaxError: […]

在Koa.js获取客户端IP

我有一个像这样的处理程序的Koa应用程序: router.get('/admin.html', function *(next) { const clientIP = "?"; this.body = `Hello World ${clientIp}`; }); 我需要获取客户端的IP地址来形成响应。 如何分配clientIp ,使其指向请求源的IP地址。