Tag: express

如何获取用户authservicelogin的currenlty的用户名

我想获得当前用户名,以便我可以显示它。 但我不知道该怎么做? 有任何想法吗 ? 我正在使用authservice这里是我的angular度控制器,我想获得用户名。 myApp.controller('meetupsController', ['$scope', '$resource', function ($scope, $resource) { var Meetup = $resource('/api/meetups'); $scope.meetups = [] Meetup.query(function (results) { $scope.meetups = results; }); $scope.createMeetup = function () { var meetup = new Meetup(); meetup.name = $scope.meetupName; meetup.$save(function (result) { $scope.meetups.push(result); $scope.meetupName = ''; }); } }]); 我的主angular控制器代码var myApp = angular.module('myApp',['ngResource','ngRoute']); myApp.config(function ($routeProvider) […]

mongodb数据库的表格和表示

我想以html的forms在node.js,express.js和angular.js中以表格forms显示mongodb数据。 我现在正在做的是这样的 route.js app.get('/superhero', function(req, res) { superhero.superhero_list(req,res); res.sendfile('./public/superhero.html'); }); superhero.js var express = require ('express') var rootRequire = require('root-require'); var bodyParser = require('body-parser'); var superheroSchema = rootRequire('Anguar/models/superhero'); module.exports = { superhero_list: function(req, res) { superheroSchema.find({}, function(err, superhero) { if (err) { return res.status(400).send({ "message": "Server error!", "err": err }); } else { return res.status(200).send({ […]

让我的React前端与我的Express服务器通话

所以我有一个运行Apache,Node和Mongo的Digital Ocean Ubuntu VPS。 我可以通过服务器上的CURL从我的数据库返回数据。 节点后端肯定在端口3000上运行。 我的React前端使用Fetch,我现在指向localhost:3000。 这是错的吗? 我也有点困惑,我的前端React包应该在我的server.js服务器上。 那很重要吗? 我可以通过我的域访问前端,它不是像我在本地工作时那样抓取数据。 我必须在我的server.js中丢失一些东西来让他们相互交stream 我阅读了关于Apache VirtualHost以及如何可能成为在单个Apache服务器上运行节点应用程序的必要组件。让我知道,如果你知道一件事或两件事。 这里是前端的httpservice.js文件: var Fetch = require('whatwg-fetch'); var baseUrl = 'http://localhost:3000'; var service = { get: function(url) { return fetch(baseUrl + url) .then(function(response) { return response.json(); }); }, post: function(url, ingredient) { return fetch(baseUrl + url, { headers: { 'Accept': 'text/plain', 'Content-Type': 'application/json' […]

快递/护照 – passport.authenticate不是一个function

我是passport.js的新手。 我一直在关注以下博客注册用户 https://scotch.io/tutorials/easy-node-authentication-setup-and-local 但每次我运行服务器,我加载/register页面显示上述错误 TypeError:passport.authenticate不是module.exports(/home/punit/Documents/****/routes/index.js:10:34)在Layer.handle [作为handle_request](/ home / punit /文件/ **** / node_modules / express / lib / router / layer.js:95:5)在trim_prefix(/home/punit/Documents/****/node_modules/express/lib/router/index.js: 312:13)at /home/punit/Documents/****/node_modules/express/lib/router/index.js:280:7 at Function.process_params(/ home / punit / Documents / **** / node_modules /express/lib/router/index.js:330:12)(/home/punit/Documents/****/node_modules/express/lib/router/index.js:271:10)在/ home /在Layer.handle [作为handle_request](/ home / punit / Documents / **** / node_modules / express / lib)处理文件/文件/ **** / node_modules / […]

psql查询没有返回正确的结果?

var searchValue = 'shahid'; var query = ("select * from students where name ilike '%"+searchValue+"%'"); 这是我的psql查询,但它没有返回任何值。 所以我只是安慰查询知道执行。 查询正在执行为: select * from students where name ilike 'hahid%' 当我把search值(Shahid)的第一个字母大写时,它完全执行。

如何在页面加载中使用Javascript成功完成Ajax请求

我正在购物车应用程序上工作。 用户将添加项目到他们的“购物车”,这是存储在本地存储。 当用户导航到他们将商品添加到购物车的不同页面时,页面需要填充他们添加到购物车的商品(本地存储)。 我正在使用handlebars为我的页面构build模板,NodeJS / ExpressJS为get / post请求创build路由和填充页面,Ajax向客户端和服务器发送请求。 目前,当用户访问视图购物车页面,我第一次通过工作,但是,我得到一个'错误:发送后无法设置标题。 这也正在以相当糟糕的方式完成。 首先,这里是我的视图购物车页面的初始获取代码: viewCart: function(req, res){ if(req.session.success){ res.render('base', {title: 'View Cart', userNav: true, checkoutNav: true, viewCart: true, cartIcon: true, js:js}); }else{ res.render('base', {title: 'View Cart', userNav: true, viewCart: true, cartIcon: true, js:js}); } }, 这只是渲染页面中没有来自本地存储的数据。 这里是我要调用的variables的html,用本地存储中的数据填充: <div id="viewCartTable"></div> 在我的JavaScript中,我有这个function,当id“viewCartTable”在那里,并执行一个ajax请求: if(document.getElementById("viewCartTable")){ var data = localStorage.getItem("Products"); Ajax.sendRequest("/user/viewCart", function(res){ responseArr […]

请求不要接收数据 – 表示js和mongo

我正在使用这个代码: app.post("/users", function(req, res) { db.collection(USERS_COLLECTION).insertOne(req.body , function(err, doc) { if (err) { handleError(res, err.message, "Failed to create new user."); } else { res.status(201).json(req.body); } }); }); 我试图把这个请求:localhost:8080 / users?firstName = foo&lastName = bar 但是当我在postman中尝试post请求时,它只返回一个id,并不会在数据库中插入params。 { "_id": "584f04eb141faa7df7fc4059" } 我该如何解决这个问题,以便它返回数据,或者我需要先创build一个模式,并检查它? 如果我能指出一个好的方向

如何在nodejs中获取头文件请求

目前正在开发elasticsearch API应用程序,我需要从服务器端的AJAX调用中获取头文件请求。 下面给出了Ajax请求。 $.ajax({ url: 'http://localhost:3002/api/v1/getAutoSuggest/'+elasticsearchIndex+'/'+elasticsearchType, dataType: 'JSONP', type: 'GET', beforeSend: function(xhr){xhr.setRequestHeader('access-control-request-headers', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9');}, success: function (data) { } }); 在nodejs中,我试图通过使用req.headers ['x-access-token']得到它,但是无法得到它。 var checkToken = app.use(function(req, res, next) { var token = req.param.token || req.headers['x-access-token']; if (token) { jwt.verify(token, config.secret, function(err, decoded) { if (err) { return res.json({ success: false, message: 'Failed to authenticate token.' }); […]

如何路由HTML节点js Express js

我试图路由多个HTML页面。 它加载index.html文件,但是当我想加载raw.html,它说 错误:无法在视图目录中查找视图“错误” app.js var routes = require('./routes/index'); var users = require('./routes/users'); var raw = require('./routes/raw'); var app = express(); // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); // uncomment after placing your favicon in /public //app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); app.use(logger('dev')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); app.use(cookieParser()); app.use(express.static(path.join(__dirname, 'public'))); app.use('/', routes); app.use('/users', users); app.use('/raw', […]

节点服务器拦截从angular(http)到java后端的所有请求

我在节点上使用express来进行路由,并使用angular作为前端框架。 我正在使用Redis进行会话。 我想要做的是,当我从angular度的http请求,它应该首先去节点,我想添加额外的头信息,如身份validation令牌,而不是传递给java(春季)后端。 我想这样做,因为如果我直接从angular度http传递信息将在networking选项卡中可见,这可能是安全漏洞。 那么如何使angular色和Java后端使用节点js服务器节点拦截器?