express

NodeJS | How to be logined after closing browser using passport and express?

自作多情 提交于 2020-01-17 06:00:52
问题 I use in my project express and passport for working with session and it works fine instead of one problem. When i close browser my session deserialized and this is fine, but i need to be logined after connecting again. Should i save information in cookies or use another package in npm? A little bit about my code: app.use(session({ secret:'secret', maxAge: new Date(Date.now() + 3600000), httpOnly: true, cookie: { path: '/', httpOnly: true, maxAge: null}, store: new MongoStore(

Why is my Express / Jade app rendering blank pages?

孤街浪徒 提交于 2020-01-17 03:36:08
问题 I just added another Jade template to my express project, and now it renders blank pages, with empty head and body tags. It works when index.jade extends layout.jade, but it breaks if layout.jade extends logo.jade. There are no errors in the console. Here is a simplified version of the project, which works fine. app.js: var express = require('express'), http = require('http'), path = require('path'), request = require('request'); var app = express(); app.configure(function(){ app.set('port',

u18next node setLng seems that doesn´t work

℡╲_俬逩灬. 提交于 2020-01-17 02:19:13
问题 I am getting a problem with the module i18next for node.js (using express). I initialize (on the app.js file) the module in this way: i18n.init({ ns: { namespaces: ['text'], defaultNs: 'text'}, resSetPath: 'locales/__lng__/new.__ns__.json', preload: ['es', 'uk', 'fr', 'ge', 'ru', 'it'], saveMissing: true, debug: true, lng:"es", sendMissingTo: 'fallback', useCookie: false, detectLngFromHeaders: false, detectLngFromPath: false }); and on the routes files I make something like this: router.get('

Express: can I use multiple middleware in a single app.use?

十年热恋 提交于 2020-01-17 02:15:09
问题 I have a lot of apps full of boilerplate code that looks like this: app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); app.use(cookieParser()); app.use(require('express-session')({ secret: 'keyboard cat', resave: false, saveUninitialized: false })); app.use(passport.initialize()); app.use(passport.session()); How can I use multiple middleware at once? So I could turn the above into: // Some file, exporting something that can be used by app.use, that runs multiple

Express: can I use multiple middleware in a single app.use?

浪尽此生 提交于 2020-01-17 02:14:05
问题 I have a lot of apps full of boilerplate code that looks like this: app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); app.use(cookieParser()); app.use(require('express-session')({ secret: 'keyboard cat', resave: false, saveUninitialized: false })); app.use(passport.initialize()); app.use(passport.session()); How can I use multiple middleware at once? So I could turn the above into: // Some file, exporting something that can be used by app.use, that runs multiple

Put method in Angular

本小妞迷上赌 提交于 2020-01-17 01:35:45
问题 I have a expressjs controller exports.update = function(req, res, next) { var id = req.params.id User.findByIdAndUpdate(id, req.body, function(err, user) { if (err) { return next(err); } else { res.json(user); } }); } and a route app.route('/api/users/:id').put(users.update); which is working fine to update user with Postman. However, my frontend part $scope.updateUser = function(id) { $http.put('/api/users/' + id, $scope.userData) .success(function(userData) { console.log(userData); })

What is the best secure way to get a JWT token from a node server from a javascript app without using a form?

梦想的初衷 提交于 2020-01-16 20:06:43
问题 In my case, I have a React app (using Next ) that need to use an API provided by a node / express / mysql app. My idea was to have an endpoint ( /login ) to provide a JWT Token based on user / password (that check the user in the database and create token based on the id of the user) and then use the JWT token to use the API endpoints (those token are stored in the mysql as well). But in order to do that, and because there is no form, I would have to store the credentials ( user and password

What is the best secure way to get a JWT token from a node server from a javascript app without using a form?

匆匆过客 提交于 2020-01-16 20:05:45
问题 In my case, I have a React app (using Next ) that need to use an API provided by a node / express / mysql app. My idea was to have an endpoint ( /login ) to provide a JWT Token based on user / password (that check the user in the database and create token based on the id of the user) and then use the JWT token to use the API endpoints (those token are stored in the mysql as well). But in order to do that, and because there is no form, I would have to store the credentials ( user and password

Express authentication - cannot send headers after sent

旧城冷巷雨未停 提交于 2020-01-16 19:41:10
问题 I have created a function that restricts route access by verifying that a stored session user/pass matches what is in the database var checkAuth = function(req, res, next){ if(typeof(req.session.user) === 'undefined') { req.session.user = { name: '', pass: '', loggedIn: false } } $R.user.validateLogin(req.session.user, function(err){ if(err) res.redirect('/login') else { req.session.user.loggedIn = true next() } }) } app.get('/restricted', checkAuth, function(req, response){ response.render(

Send object from node.js to ejs, not [object Object]

心已入冬 提交于 2020-01-16 19:28:26
问题 If you use node.js and ejs and render JavaScript object to ejs, the resultant HTML page has the following syntax: [object Object] despite the fact that my object is as follows: [{"a": 3, "b": 10}, {"c":3, "d":20}, {"e":1, "f":55}] However, I want to render the object itself (object literal if I understand it correctly), not the useless [object Object] . So how can I render it properly? res.render("index", {result: listOfObject.valueOf()}) didn't work. 回答1: [object Object] is what you get when