Tag: express

如何从App Engine获得真正的请求客户端的IP

我已经设置了app.set('trust_proxy', 1); 就像本页build议,但每个请求它给出以下IP地址169.254.160.2 … req.ip => 169.254.160.2 req.ips => [ '169.254.160.2' ] 标题build议标题也具有相同的值…所以我如何得到IP因为所有“什么是我的IP”网站告诉我,我的IP是130.204.67.112 那么如何让我的真正的IP在App引擎? PS。 我使用自定义的docker容器为我的应用程序,如果重要的话(我认为它不可能,但仍然)我已经从heroku移植它需要app.enable('trust_proxy') ,它确实工作。

将Express NodeJS的值传递给AngularJS控制器variables

我想从快速NodeJS服务器传递一些值到AngularJS控制器variables。 这里是代码片段…. 服务器 app.post('/run-engine', function(req, res){ console.log(req) res.writeHead(200, {'Content-Type': 'text/html'}); fs.readFile('index.html', 'utf-8', function(err, content) { if (err) { res.end('error occurred'); return; } var reconData = 'some temp'; //here I assign temp variable with needed value var renderedHtml = ejs.render(content, {data: reconData}) res.end(renderedHtml); }); }); HTML代码片段 <section class="mdl-layout__tab-panel tab2" id="scroll-tab-2"> <div class="page-content"> <h1>This is Tab2</h1> Data: […]

Angular $ http.get和Express req.body是空的

我有使用$ http.get发送数据的req.body问题。 当我在route.js方法从GET更改为POST,并在我的服务更改为$ http.post时,一切工作正常,但与GET我不能发送任何数据到我的服务器节点。 任何人有任何想法? server.js // modules ================================================= var express = require('express'); var app = express(); var mongoose = require('mongoose'); var bodyParser = require('body-parser'); var methodOverride = require('method-override'); var path = require('path'); // configuration =========================================== var db = require('./config/db'); var port = process.env.PORT || 8080; mongoose.connect(db.url); app.use(express.static(__dirname + '/public')); app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); […]

如何从angularjs $ http.post中读取/保存nodeJs中的json文件

厌恶糟糕的英语 我有一个问题,试图抓住一个json使用$ http.post fron一个angularjs发送到一个nodejs express(我必须发送它,因为我不能在客户端保存在服务器上的文件) 我有这个代码在angularjs var app = angular.module('angularTable', []); app.controller('listdata',function($scope, $http){ $scope.users = []; //declare an empty array $http.get("data/people.json").success(function(response){ $scope.users = response; //this works well }); $scope.add = function(){ $scope.users.push({'id':$scope.users.length,'name':$scope.name,'age': $scope.age}); //this works well $http.post("data",$scope.users).success(function(data, status, headers, config){ //this send to the nodeJs the object console.log("success"); }).error(function(data,status,headers,config){ console.log("error"); }); } }); 这在服务器nodeJs中 var […]

在可组合中间件中处理Express-JWT错误

我正在为每个API实现JWT授权,如下所示: auth.js import expressJwt from 'express-jwt'; import compose from 'composable-middleware'; var validateJwt = expressJwt({ secret: config.secrets.session }); function isAuthenticated() { return compose() .use(function(req, res, next) { validateJwt(req, res, next); }) .use(function(req, res, next) { User.find({ where: { id: req.user.id } }).then(function(user){ //Handle User }).catch(function(err){ //Handle DB Error }); }); } index.js import auth from '../../auth'; […]

Mongoose / NodeJS – 来自数据库的string被检索,但被视为未定义

这是我现在的问题: 我查询findOne并填充我的数据库为了检索我的.EJS使用的string数组,但日志说,价值没有定义,但它给的价值的名称:“ string名称未定义” 我一定错过了什么.. 这是用户架构: var UserSchema = new mongoose.Schema({ username: { type: String, required: true, index: { unique: true } }, email: { type: String, required: true, index: {unique: true } }, password: { type: String, required: true }, tables: [{ type: Schema.Types.ObjectId, ref: 'Table' }], resetPasswordToken: String, resetPasswordExpires: Date, uuid: String, }); 这是表格模式: […]

我应该如何使用MEAN堆栈来处理我的后端devise?

这可能更多是寻找build议的情况。 但是,我将提供示例代码作为我想要实现的示例。 我正在尝试构build我的第一个后端系统,并且一直在遇到devise问题。 我的MongoDB数据库由四个主要部分组成 – configuration文件,团队,草稿和用户。 configuration文件(是使用ID来源的所有主要数据)架构具有用于保存具有团队和草稿ID的数组的属性。 这个想法是,当configuration文件被提供时,它将通过使用ID来填充所有这些属性和相关数据。 使用Mongoose的configuration文件模式的示例: var mongoose = require('mongoose'); var Schema = mongoose.Schema; var UserProfileSchema = new Schema({ Name : String, Email : String, Admin : Boolean, Status : Number, UserID : String, PrivateProfile: Boolean, Drafts: [String], //This array holds the draft IDs Teams:[String] //Holds the team profiles IDs }); module.exports […]

在调用ExpressJS REST路由时奇怪的行为

我正在制作一个包装TMDb API的简单REST服务器。 而且我正在使用MovieDB Node模块,它具有通过提供API密钥直接调用TMDb的API的function。 我有以下应用程序文件夹结构。 myproject | —configuration.json —index.js —app.js —/routes | — index.js — /movie | — index.js 在myproject/index.js ,我有一个简单的启动Express服务器的脚本, app.js是我在初始化路由的地方。 MyProject的/ app.js 路线如何初始化 var myApp = require("express")(), configuration = require("./configuration.json"); myApp.locals.tmdbApiKey = configuration.tmdbApiKey; myApp.use('/api', require('./routes')); 如上所示,服务器的API根目录为localhost:9000/api/ (我在端口9000上运行它)。 的myproject /路线/ index.js 以下是我如何加载movie路线。 var router = require('express').Router(); router.use('/movie', require('./movie')); MyProject的/路线/电影/ index.js 最后,我已经定义了如下的终点。 var router = […]

在节点js中,mongo中的$ invariablesreplace不起作用

我已经构build了/57639afa5961debc1b256745/, /5763c5d17d05688c1838c7a3/,节点path/57639afa5961debc1b256745/, /5763c5d17d05688c1838c7a3/,但是当我尝试使用nodepath /57639afa5961debc1b256745/, /5763c5d17d05688c1838c7a3/,即使它有子节点/57639afa5961debc1b256745/, /5763c5d17d05688c1838c7a3/,得到空数组的结果: Degree.prototype.findByPath = function(dbObj, degrees) { var nodePath = ''; for(var i in degrees) { nodePath = nodePath + '/' + degrees[i]['_id'] + '/, '; } return new Promise(function (resolve, reject) { console.log(nodePath); dbObj.collection('degree').find({ 'path': { '$in': [ nodePath ] } }).toArray((err, results) => { if(err) { reject(err); } else […]

Node.js如何将geojson从mongodb传递给我可以在前端使用的对象

我正在尝试将存储在mongoDB中的5m点进行聚类。 1查询的最大结果目前只有1米左右,所以我决定使用: PruneCluster作为第一个视觉效果。 点存储为geoJSON对象,并在其上有2dsphere索引。 我使用本机node.js驱动程序连接到mongodb并查询以find多边形内的点,这将只会从集合和路由结果中返回loc字段以进行预览: router.get('/map', function(resq,res) { var MongoClient = mongodb.MongoClient; var url = 'mongodb://localhost:27017/airboost'; MongoClient.connect(url, function(err, db) { if(err){ console.log('Unable to connect to db ', err); } else { console.log('Connected!!!'); var collection = db.collection('listingsF'); collection.find({ loc: { $geoWithin: { $geometry: { type : "Polygon" , coordinates: [[[121.48521363894814,31.41360430073249],[…],[121.48865692654915,31.41168940543709]]] } } } },{loc:1}).toArray(function(err, result){ if […]