express

Express req.query always empty

六月ゝ 毕业季﹏ 提交于 2020-08-27 21:32:11
问题 I was using express route like this and I want my urls to contain query strings initially. app.get('/', function(req, res){ res.render('index', {}); }); app.get('/us01', function(req, res){ console.log('query: '+JSON.stringify(req.query)); res.render('templates/us01', {}); }); app.get('/benchmark', function(req, res){ res.render('templates/benchmark', {}); }); However, I never get my query strings printed no matter what query strings I append after /us01. For example, "localhost:9200/us01?a=1

Express req.query always empty

旧城冷巷雨未停 提交于 2020-08-27 21:29:03
问题 I was using express route like this and I want my urls to contain query strings initially. app.get('/', function(req, res){ res.render('index', {}); }); app.get('/us01', function(req, res){ console.log('query: '+JSON.stringify(req.query)); res.render('templates/us01', {}); }); app.get('/benchmark', function(req, res){ res.render('templates/benchmark', {}); }); However, I never get my query strings printed no matter what query strings I append after /us01. For example, "localhost:9200/us01?a=1

Calling an internal API from within Express

醉酒当歌 提交于 2020-08-27 16:02:46
问题 I have a simple API route set up in Express (consumed mainly via my Angular frontend): app.post('/api/sendEmail', emailApi.sendEmail); I've made a module that sits in my backend and also needs to call this service. I figured the easiest way was to do a POST request: request({ url: '/api/sendEmail', method: 'POST', json: { template: template.toLowerCase(), obj: mailObj } }, function(error, response, body){ console.log('error', error); console.log('response', response); console.log('body', body

Rendering html with data with nodejs Express

坚强是说给别人听的谎言 提交于 2020-08-26 08:29:39
问题 I'm new to express framework i just want know how to render html page with some data from mongo DB i used below code to send html but not sure how to send some data res.sendFile(path + "feature.html"); this is success as html get renders send data like this ?? res.sendFile(path + "feature.html", {data: data}); how to display data in html ?? if i have sent an array like this res.sendFile(path + "feature.html", {data: []}); how to loop this in html ?? 回答1: I suggest you to use some template

Heroku Error: ENOENT: no such file or directory, open '.env'

我是研究僧i 提交于 2020-08-26 07:38:21
问题 I'm trying to push my application to Heroku, but I'm running into some issues: Error: ENOENT: no such file or directory, open '.env' 2019-04-10T01:38:23.050188+00:00 app[web.1]: 1 at Object.openSync (fs.js:438:3) 2019-04-10T01:38:23.050190+00:00 app[web.1]: 1 at Object.readFileSync (fs.js:343:35) 2019-04-10T01:38:23.050192+00:00 app[web.1]: 1 at Object. (/app/config/database.js:4:39) It seems that the error is the variable envConfig , but i need it for database to work. As of now, I'm getting

Heroku Error: ENOENT: no such file or directory, open '.env'

≯℡__Kan透↙ 提交于 2020-08-26 07:37:35
问题 I'm trying to push my application to Heroku, but I'm running into some issues: Error: ENOENT: no such file or directory, open '.env' 2019-04-10T01:38:23.050188+00:00 app[web.1]: 1 at Object.openSync (fs.js:438:3) 2019-04-10T01:38:23.050190+00:00 app[web.1]: 1 at Object.readFileSync (fs.js:343:35) 2019-04-10T01:38:23.050192+00:00 app[web.1]: 1 at Object. (/app/config/database.js:4:39) It seems that the error is the variable envConfig , but i need it for database to work. As of now, I'm getting

Express : Call to next in error handler

非 Y 不嫁゛ 提交于 2020-08-26 07:14:49
问题 I am implementing a node + express js app, and I am having issues calling to the next function into the error handler. I have a render middleware which is called by next in each each controler, and I would like it to be the same with my error handler. What I do in controler is putting some viewProperties in the req and then call the next middleware which retrieve these properties and render the response consequently. function render(req, res, next) { // viewName, title, args var properties =

How to prevent non-browser clients from sending requests to my server

旧街凉风 提交于 2020-08-24 03:59:49
问题 I've recently deployed my website and my back-end on the same vps, using nginx, but now when I do a request with PostMan to http://IP:port/route - I get the response from the server from any PC. I think this not how its suppose to work. I set the CORS options to origin : vps-IP (so only my domain), but my server still accepts the requests from PostMan. Is there any way to prevent my back-end from accepting these requests limiting the domain to only my domain AKA my vps ip? And must the

How to prevent non-browser clients from sending requests to my server

亡梦爱人 提交于 2020-08-24 03:59:03
问题 I've recently deployed my website and my back-end on the same vps, using nginx, but now when I do a request with PostMan to http://IP:port/route - I get the response from the server from any PC. I think this not how its suppose to work. I set the CORS options to origin : vps-IP (so only my domain), but my server still accepts the requests from PostMan. Is there any way to prevent my back-end from accepting these requests limiting the domain to only my domain AKA my vps ip? And must the

node and reactjs axios server request returning index.html file instead of json

假如想象 提交于 2020-08-22 07:09:07
问题 I have setup my project with a react frontend being compiled by webpack and the server running on node and express. When I deploy to production my requests to the server are returning the index.html file in the 'dist' folder rather than the json with the data. My webpack compiled output is at the location ./dist. Here is the routing part of my server.js file: if (process.env.NODE_ENV === 'production') { app.use(express.static('dist')); const path = require('path'); app.get('/', (req, res) =>