express

What is the correct way to “end” a request from express/connect middleware?

余生长醉 提交于 2020-05-12 11:14:14
问题 Assuming I have middleware such as this; var express = require('express'); var app = express(); app.use(function (req, res, next) { var host = "example.com"; if (req.host !== host) { res.redirect(301, host + req.originalUrl); res.end(); } }); What sort of rules do I need to abide by here? Should I be calling res.end() ? (or does res.redirect() do this for me?) Should I be calling next() ? (or does connect detect the request has ended and exit cleanly?) Assuming that I should be calling next()

Express Handlebars Won't Render Data

给你一囗甜甜゛ 提交于 2020-05-11 17:48:41
问题 I am working with NodeJS and Express using Express-Handlebars template engine. Handlebars is throwing the following error when trying to render a template: Handlebars: Access has been denied to resolve the property "username" because it is not an "own property" of its parent. You can add a runtime option to disable the check or this warning: See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details According to the above link: From version

Express Handlebars Won't Render Data

浪子不回头ぞ 提交于 2020-05-11 17:48:12
问题 I am working with NodeJS and Express using Express-Handlebars template engine. Handlebars is throwing the following error when trying to render a template: Handlebars: Access has been denied to resolve the property "username" because it is not an "own property" of its parent. You can add a runtime option to disable the check or this warning: See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details According to the above link: From version

React Routing works in locally but not Heroku

假如想象 提交于 2020-05-11 07:28:48
问题 My issue here is incredibly similar if not exactly the same as the one outlined in this issue. Unfortunately, I haven't been able to resolve it using the strategy it provides. So here are my own details: I am using Create React App , React Router 4 , Express , and Heroku and have followed the instructions here with regards to setting up a server with CRA. Locally, I am able to access routes such as myapp/about , yet after building and pushing to heroku, these 404. I can navigate to this route

Passport js local strategy custom callback “Missing credentials”

a 夏天 提交于 2020-05-11 07:17:34
问题 I have a really annoying problem with Node js, express 4 and passport. I have tried all options I can think of, but still no solution. Couldn't find a solution from other posts for this problem. Code: app.post('/login', function(req, res, next) { console.log(req.body.user_email); console.log(req.body.user_password); passport.authenticate('local', function(err, user, info) { console.log(info); ... The problem is that for some reason, passport does not get the credentials and says at the

How to get cookie value in expressjs

一世执手 提交于 2020-05-10 04:04:37
问题 I'm using cookie-parser, all the tutorial talk about how to set cookie and the time it expiries but no where teach us how to get the value of these cookie 回答1: First note that Cookies are sent to client with a server request and STORED ON THE CLIENT SIDE . Every time the user loads the website back, this cookie is sent with the request. So you can access the cookie in client side (Eg. in your client side Java script) by using document.cookie you can test this in the client side by opening the

How to get cookie value in expressjs

主宰稳场 提交于 2020-05-10 04:04:21
问题 I'm using cookie-parser, all the tutorial talk about how to set cookie and the time it expiries but no where teach us how to get the value of these cookie 回答1: First note that Cookies are sent to client with a server request and STORED ON THE CLIENT SIDE . Every time the user loads the website back, this cookie is sent with the request. So you can access the cookie in client side (Eg. in your client side Java script) by using document.cookie you can test this in the client side by opening the

About app.listen() callback

时光毁灭记忆、已成空白 提交于 2020-05-09 19:09:48
问题 I'm new in javascript and now i'm learn about express.js, but i get some code that makes me confused about how they work. I was tring to figure out how this code work but i still don't get it: var server = app.listen(3000, function (){ var host = server.address().address; var port = server.address().port; console.log('Example app listening at http://%s:%s', host, port); }); My question is how this anonymous function can using the server variable, when the server variable getting return value

About app.listen() callback

余生长醉 提交于 2020-05-09 19:08:56
问题 I'm new in javascript and now i'm learn about express.js, but i get some code that makes me confused about how they work. I was tring to figure out how this code work but i still don't get it: var server = app.listen(3000, function (){ var host = server.address().address; var port = server.address().port; console.log('Example app listening at http://%s:%s', host, port); }); My question is how this anonymous function can using the server variable, when the server variable getting return value

Send update notification to particular users using socket.io

你离开我真会死。 提交于 2020-05-09 18:55:54
问题 Following is the code on front end, where storeSelUserId contains user_id to send the message- FYI - Node Version 1.1.0 // Socket Notification var socket = io('http://localhost:6868'); socket.on('connection', function (data) { socket.emit('send notification', { sent_to: storeSelUserId }); }); Following is the server code in routes file - var clients = {}; io.on('connection', function (socket) { socket.emit('connection', "Connection Created."); socket.on('send notification', function (sent_to)