express

Sorting query results by the order of items in provided conditions array in Mongoose

我是研究僧i 提交于 2020-02-05 05:17:10
问题 I am looking for a way to query a database with Mongoose based on an array of document IDs and return the results in the order in which they were presented to Mongoose within that array. For example if I provided Mongoose with this array ["112", "111", "113"] and assuming that all the documents with these IDs exist the result will be an array of documents ordered accordingly as: [{//112},{//111},{//113}] Just to be crystal clear, I don't need to sort the array by any specific document field -

server sent events creates way too many listeners for single client

家住魔仙堡 提交于 2020-02-05 03:51:56
问题 I am using server sent events in MEAN stack. I am able to push data from server to client whenever required. But one thing i noticed that even if i am the only client hitting the server. There are multiple listeners for me and events are broadcast to say 40 listeners ( if i wait long enough for the client to reconnect 40 times ). Multiple listeners are also created when user reloads . How can i limit the listeners to say 1 listener to per event per client . Is this even possible with server

Redirect nodejs express static request to https

馋奶兔 提交于 2020-02-03 10:10:11
问题 I need to redirect all http requests to https including request to static files. My code: app.use(express.static(__dirname + '/public')); app.get('*', function(req, res) { if (!req.secure){ return res.redirect('https://' + config.domain + ":" + config.httpsPort + req.originalUrl); } res.sendFile(__dirname + '/public/index.html'); }); And redirect not working on static files. If I change order: app.get(...); app.use(...); Then my static not working. How to redirect on such requests? 回答1: var

Redirect nodejs express static request to https

喜欢而已 提交于 2020-02-03 10:09:09
问题 I need to redirect all http requests to https including request to static files. My code: app.use(express.static(__dirname + '/public')); app.get('*', function(req, res) { if (!req.secure){ return res.redirect('https://' + config.domain + ":" + config.httpsPort + req.originalUrl); } res.sendFile(__dirname + '/public/index.html'); }); And redirect not working on static files. If I change order: app.get(...); app.use(...); Then my static not working. How to redirect on such requests? 回答1: var

How to stop Firebase auth handled backend from carrying on to other browsers / sessions

ぐ巨炮叔叔 提交于 2020-02-02 17:45:26
问题 I'm in the process of creating an authentication based web app. It works fine when only one session is running, but if a user on another session is logged in, it carries through to all sessions allowing everyone to see that user's information and use their permissions. I've determined that this is because I handle all of my authentication backend from this post: Firebase Auth : User session carried to different browser But I'd like to know whether there are any fixes without having to handle

How to stop Firebase auth handled backend from carrying on to other browsers / sessions

喜欢而已 提交于 2020-02-02 17:45:18
问题 I'm in the process of creating an authentication based web app. It works fine when only one session is running, but if a user on another session is logged in, it carries through to all sessions allowing everyone to see that user's information and use their permissions. I've determined that this is because I handle all of my authentication backend from this post: Firebase Auth : User session carried to different browser But I'd like to know whether there are any fixes without having to handle

How to fix wrong proxy redirection from sub path from React.js using React Router?

亡梦爱人 提交于 2020-02-02 12:31:24
问题 I'm making a multi-pages app with React Router and I'm using Node for the backend. Node is working on the port 3000 and React on the port 3001. I have set up a proxy in package.json of the front-end(React). My API is reachable on localhost:3000/api/ So my get or post from the frontend(port:3001) with axios look like this: axios.post('api/login/',{data........}) It is working perfectly from a parent path like /item or /example http://localhost:3001/xxxxxx/ ... I can reach my /api/login on port

How to fix wrong proxy redirection from sub path from React.js using React Router?

☆樱花仙子☆ 提交于 2020-02-02 12:31:12
问题 I'm making a multi-pages app with React Router and I'm using Node for the backend. Node is working on the port 3000 and React on the port 3001. I have set up a proxy in package.json of the front-end(React). My API is reachable on localhost:3000/api/ So my get or post from the frontend(port:3001) with axios look like this: axios.post('api/login/',{data........}) It is working perfectly from a parent path like /item or /example http://localhost:3001/xxxxxx/ ... I can reach my /api/login on port

Where to place the front-end javascript files?

痞子三分冷 提交于 2020-02-02 10:13:22
问题 I am developing an express based web application and I started following the application skeleton built by express-generator. Next, I added to my project webpack to bundle the client side assets. Now I am not sure where to place the front-end javascript files, if in a /src or /app folder? In truth, I am in a dilemma between, app.js , /lib , /src and /app folders. According to express-generator, it creates an app.js file as the main entry and thus it looks a little bit strange to have an app

Is there a way or a trigger to notify when there is an error and restart happened with PM2

筅森魡賤 提交于 2020-02-02 03:50:08
问题 I have an express application running and I am using PM2 to keep it alive and restart when there is any error in the system. PM2 logs the error and restarts which is perfectly fine. But I need to notify the user who submitted this with the error message. Is there any way or event or trigger which is activated when the restart happens or when the error is being written to the log file so that I can try to capture that and notify the actual user? I implemented as per suggestion below, var pm2 =