express

Where to terminate SSL/TLS in Node & Nginx

僤鯓⒐⒋嵵緔 提交于 2021-01-29 01:54:49
问题 I'm building a web application using the MEAN stack. The site contains authentication (using passport.js) so I would like to secure our connection with SSL/TLS. For our deployment we're using nginx as a reverse proxy to the Node app running on the same AWS EC2 instance. My question is: With my setup, what is the best practice way to setup an https (SSL/TLS) connection? Should I get a certificate and set it up at the nginx layer? Should I do it in my node app directly? Is there some other

Custom middleware express.js framework ordering

℡╲_俬逩灬. 提交于 2021-01-28 22:04:12
问题 I am writing custom middleware(s) to send request data(like request path, response code, request timestamp, etc) to a remote server on every request. I'm unable to figure out the ordering of my middlewares. I have created 2 middlewares, a) process_request (m1) --> this middleware just adds a timestamp to the request object to register when the request was received. b) process_response (m2) --> this middleware posts the required data to the remote server m1 function process_request(req, res,

API routes on react + express app giving 404 on Heroku

非 Y 不嫁゛ 提交于 2021-01-28 21:06:07
问题 So I built a simple mern app that works fine on my local environment, but when deploying to Heroku, it serves the react app fine but 404s on the API calls. I can't seems to figure out the issue. I'm sending requests using Axios. I checked the network requests and they all look good, but still come back 404. testing in postman also returned the same error. Here's the server code... Any idea why this is failing? const express = require('express'); const path = require('path'); const Axios =

API routes on react + express app giving 404 on Heroku

点点圈 提交于 2021-01-28 20:32:39
问题 So I built a simple mern app that works fine on my local environment, but when deploying to Heroku, it serves the react app fine but 404s on the API calls. I can't seems to figure out the issue. I'm sending requests using Axios. I checked the network requests and they all look good, but still come back 404. testing in postman also returned the same error. Here's the server code... Any idea why this is failing? const express = require('express'); const path = require('path'); const Axios =

Problem running express app with pm2 using ecosystem config file

你说的曾经没有我的故事 提交于 2021-01-28 20:23:52
问题 When I run my Node.js express app using node command everything works fine! When using pm2 server ./bin/www` my pm2 status is something like this: And my app works in this situation. Also when I use pm2 start bin "./bin/www" -i 0 my pm2 list shows: And yet again my app works. But using following config file: module.exports = { apps: [{ name: 'cdn', script: './bin/www', instances: 0, exec_mode: 'cluster', watch: true, env: { NODE_ENV: 'production', PORT: process.env.PORT || '5555', } }] }; the

node res.render changes view but not url

本秂侑毒 提交于 2021-01-28 18:59:57
问题 I am sending an id from a jade view to its controller (backend), the controller then queries mongodb and the result is sent to a new jade view - angular . The results & view appear but URL stays the same (previous view), thus if I F5 the current view, it reloads the previous view. So the route is: view->node->angular Ideas? jade launcher view form(method="post") input(type="hidden" name="id" value=cart._id) input(type='hidden', name='_csrf', value=_csrf) button.btn.product.btn-primary(type=

Check if res is sent / ended with Express

China☆狼群 提交于 2021-01-28 18:20:41
问题 Using Express, how can I determine the response has been sent / that the response has been completely written to? app.use((req,res,next) => { if(res.ended){ // } if(res.finished){ // } }); how can I tell if res.end() has been called? I am looking for a boolean I can read on res. 回答1: response.end() will set response.finished if it's been called, as per the documentation. 回答2: Use res.writableEnded (docs). res.finished is deprecated (see). 来源: https://stackoverflow.com/questions/57618325/check

how to detect whether file download successfully from client side in mean/angular js

为君一笑 提交于 2021-01-28 18:06:42
问题 I have created a chat application in which I have kept file sending functionality over chat windows. Now I want to remove files from the server end when clients successfully download them. I'm using the MEAN stack. router.post("/postChatFileSend",ensureAuthenticatedForPost,function(req,res) { if (req.body.fileName) { var filePath = __dirname + '/../public/ChatFile/'+req.body.fileName; fs.unlink(filePath, function (err) { }) }; return res.json({"status": true,"messages":"messages read

displaying collection data from mongodb using axios in reactjs

徘徊边缘 提交于 2021-01-28 15:16:18
问题 I am new to MERN and I try to display data from mongodb collection using axios. I try to display a list of cities on the web page. I am not sure if I am doing it write. Should I use super state?jsonpostman Here is my reactjs code: import React, { Component } from 'react'; import axios from 'axios'; export class Cities extends Component { constaractor(state) { state = { locations:[] }; } componentDidMount() { axios.get('/cities') .then(cities => console.log(cities.data)) .catch(e => console

displaying collection data from mongodb using axios in reactjs

余生长醉 提交于 2021-01-28 15:12:12
问题 I am new to MERN and I try to display data from mongodb collection using axios. I try to display a list of cities on the web page. I am not sure if I am doing it write. Should I use super state?jsonpostman Here is my reactjs code: import React, { Component } from 'react'; import axios from 'axios'; export class Cities extends Component { constaractor(state) { state = { locations:[] }; } componentDidMount() { axios.get('/cities') .then(cities => console.log(cities.data)) .catch(e => console