Tag: express

护照通过Google reCaptcha进行身份validation

我正在尝试将google reCaptchajoin到我的registry单的后端,这个后端已经有了护照authentication,代码如下: app.get('/signup', function(req, res) { // render the page and pass in any flash data if it exists res.render('signup.ejs', { message : req.flash('signupMessage') }); }); app.post('/signup', passport.authenticate('local-signup', { successRedirect : '/app', // redirect to the secure chat section failureRedirect : '/signup', // redirect back to the signup page if there is an error failureFlash […]

无法在React服务器端呈现中处理UnhandledPromiseRejectionWarning

我有一个在客户端和服务器上呈现的React应用程序。 当任何组件的render()失败时(由于我的代码中有一个bug,例如试图读取一个未定义的对象的属性),那么如果我从浏览器的另一个页面导航,那么我得到一个完整的堆栈跟踪浏览器开发者控 但是,当我触发服务器端的相同代码的呈现(通过直接将浏览器指向包含有问题的组件的有问题的路由),那么我只是在服务器的控制台中得到这样的错误: (node:97192) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'tagDefinitionId' of undefined 没有堆栈跟踪,debugging有点困难。 问题: 在服务器端渲染过程中是否有一种方法可以覆盖所有的render()失败? 下面是触发服务器端呈现以响应请求的Node-Express端点的代码。 我相信renderToString()内部发生了未处理的承诺拒绝,但是这个函数返回一个string,而不是一个承诺。 ` import configureStore from '../../redux/store'; import { renderToString } from 'react-dom/server'; import { Provider } from 'react-redux'; import React from 'react'; import RouterContext from 'react-router/lib/RouterContext'; import createMemoryHistory from 'react-router/lib/createMemoryHistory'; import match from […]

在Sequelize中不起作用

我目前正在使用ExpressJS,PostgreSQL和Sequelize作为ORM的项目。 我开发了一个searchfunction,使查询按名称search项目: models.foo.findAll({ where: { $or: [ {name: {$ilike: keywords}}, {searchMatches: {$contains: [keywords]}} ] }, order: [['name', 'ASC']] }) 这工作正常,但如果名称包含特殊字符(如á,é,í,ó或ú),该查询将无法find它。 有没有办法使查询search名称与speacial字符在一个有意义的意义? 就像我search名字“马铃薯”的结果“马铃薯”,“大锅饭”和“我们是pótatóes”将出来,而不是“我们吃pátatos”(因为á!= o)

用post api将数据保存到mongodb

我有我的API文件中的职位function。 我想要保存一个电子邮件在MongoDB数据库使用这个post请求: rest-api/emails?from="test@mail.com"&"to"="test@test.com"&subject="some subject"&content="some more content"&provider=sendgrid&success=false 我发布的方法如下所示: .post((req, res)=>{ db.models.Email.create({from:req.body.from , to: req.body.to, subject: req.body.subject, content: req.body.content, success: req.body.success, provider: req.body.provider}, (err, result)=>{ if(err){ handleErrors(res, err); console.log(`error in creating Email :${err}`) }else { console.log() res.json(result) } }); }); 经过这个职位请求只有_id , success , provider领域保存在mongodb。 我怎样才能解决这个问题 ? 编辑:我删除所有“发布请求,但仍然没有正确保存: localhost:3000/rest-api/emails?from=example@example.com&to=test@test.com&subject=somesubject&content=somemorecontent&provider=sendgrid&success=false RES: { "__v": 0, "_id": "599add615fcb202b34c6a13e", "success": false, […]

CRUD nodejs / express server:app.put req.body是空的

我刚刚写了一个基本的crud操作的超简单nodejs后端。 然而,在陈述声明中,我没有收到我的请求的正文: app.put('/note-update/:id', function (req, res) { var noteId = req.params.id; console.log(req.body) db.collection('notes').update({ _id: noteId }, req.body, (err, result) => { res.send( (err === null) ? { msg: req.body } : { msg: err } ); }); }); 这是我用ajax执行的调用: var note = { _id: "599e660cbc845b4e2952715f", name: "Genauer Detailbeschrieb", note: "Ey-10" } $.ajax({ type: 'PUT', url: […]

麻烦callback,错误捕获和MongoDB

我一直在研究一个允许我将公司添加到数据库的应用程序。 原来我的代码是纯意大利面,所以我想正确模块化。 为此,我添加了路线,一个控制器和一个道。 这就是我的代码现在的样子 路线 app.post('/loadcompanies', (req, res)=> { companiesController.loadcompany(req.body, (results)=>{ console.log(results); res.send(200, "working!"); }) }) 调节器 module.exports.loadCompany = (body, callback)=>{ companiesDao.loadCompany(body, callback); } 道 module.exports.loadCompany = (company, callback)=>{ MongoClient.connect(conexionString, (err, database) => { if (err) console.log(err); db = database; console.log(company); db.collection('companies').insert(company, (err, result)=>{ callback({message:"Succesfully loaded company", company:result}); }); }) } 我目前的担心是,模块化这样的错误工作是令人困惑的。 我试图添加一个try-catch的方法,如果有一个db插入和抛出和错误,但似乎并没有工作。 我试过的其他事情是在callback中返回错误,如下所示: if […]

如何将一个POST请求转发到两个外部URL?

我们使用的一个SaaS提供商有一个webook字段,但只允许input一个url。 事实上,我们需要将这个webhook发送到两个分析服务,所以我需要找出一个方法来编写一个自定义端点,将整个请求转发到我们需要的其他端点(目前为2个)。 用node和express做这个最简单的方法是什么? 如果我没有弄错,简单的redirect不适用于多个POST,对吧? 我不确定头文件甚至是请求内容是什么样子的,但是如果auth在头文件中,它需要尽可能地保留。 这是我迄今为止,但它是远远不够完整: app.post('/', (req, res) => { console.log('Request received: ', req.originalUrl) const forwardRequests = config.forwardTo.map(url => { return new Promise((resolve, reject) => { superagent .post(url) .send(req) .end((endpointError, endpointResponse) => { if (endpointError) { console.error(`Received error from forwardTo endpoint (${url}): `, endpointError) reject(endpointError) } else { resolve(endpointResponse) } }) }) }) Promise.all(forwardRequests) […]

NodeJS Express Docker实例退出,代码为0

目标 我在我的dockercompose.yml有3个实例,我只能启动2个实例,并且难以启动我的节点expression的第三个实例。 项目目录 . ├── Icon\r ├── angular │ ├── Dockerfile │ ├── README.md │ ├── dist │ │ ├── css │ │ │ └── style.css │ │ ├── img │ │ │ ├── external.png │ │ │ ├── favicon.png │ │ │ ├── footer_logo.png │ │ │ └── logo.png │ │ ├── index.html │ […]

将数据发布到mongoDb后如何获得id?

我正在使用node.js,angularjs和mongoDb。 我正在创build一个产品上传页面。 它分为两部分: 数据页面 :这部分将包含文本框和下拉菜单。 图片上传页面 :这个部分会有图片上传控件。 所以我想在同一页面创build2个表单,从第一页我将文本数据发布到mongoDb,返回新创build的产品的product_id ,然后上传带有返回的product_id的图像。 我开发了restFul API来发布产品api/products/create-product 。 产品型号 : { productName:{type: String}, productPrice:{type: Number} } 图像模型 : { productId:{type: String}, imagePaths:[{type: Array}] } 产品控制器(Angular): $scope.newProduct = function(){ var formData = new FormData; for(key in $scope.product){ formData.append(key, $scope.product[key]); } //getting the files var file = $('#file')[0].files[0]; formData.append('image', file); //Post data $http.post('http://localhost:3000/products/api/new-product',formData,{ […]

如何获得插入查询logging集

我正在使用mssql。 插入一条logging后,我想获取数据的ID。 但我不知道这么做。 我的代码如下。 请给我答案。 var mssql = require('mssql'); mssql.connect(config.mssql, function(err) { var request = new mssql.Request(); request.query('insert —–'),function(err, data) { console.log(data); } 插入工作正常,但控制台日志是[未定义] …. 这是表格的ddl SET ANSI_NULLS ON 走 SET QUOTED_IDENTIFIER ON 走 CREATE TABLE [dbo]。[Feature]( [id] nvarchar NOT NULL CONSTRAINT [DF_Feature_id] DEFAULT(CONVERT(nvarchar,newid(),(0))), [createdAt] datetimeoffset NOT NULL CONSTRAINT [DF_Feature_createdAt] DEFAULT(CONVERT(datetimeoffset,sysutcdatetime(),(0))), [updatedAt] datetimeoffset NULL, [版本] […]