express

Firebase Functions : How to store simple cookies to remember an authenticated user

谁说胖子不能爱 提交于 2020-06-13 18:03:49
问题 I'm trying to just remeber a user returning to the site and count views, only after 5 minutes. I did this, works when using Firebase Serve , but the cookies are not being stored after deploy. Somewhere up in the app. app.use(cookieSession({ name: 'session', keys: ['utl__key_s1', 'utl__key_s2'] })); Trying to check if session exists and isn't more than 5 min old. function sessionExists(req) { const t = req.session.viewTime; if (t == null) { req.session.viewTime = + new Date(); return false; }

Firebase Functions : How to store simple cookies to remember an authenticated user

好久不见. 提交于 2020-06-13 18:02:57
问题 I'm trying to just remeber a user returning to the site and count views, only after 5 minutes. I did this, works when using Firebase Serve , but the cookies are not being stored after deploy. Somewhere up in the app. app.use(cookieSession({ name: 'session', keys: ['utl__key_s1', 'utl__key_s2'] })); Trying to check if session exists and isn't more than 5 min old. function sessionExists(req) { const t = req.session.viewTime; if (t == null) { req.session.viewTime = + new Date(); return false; }

how to mock configurable middleware in node js with sinon and mocha

纵饮孤独 提交于 2020-06-13 09:07:48
问题 I have configurable middleware where I can pass parameters and based on that it calls next function. middleware code: File: my-middleware.js exports.authUser = function (options) { return function (req, res, next) { // Implement the middleware function based on the options object next() } } var mw = require('./my-middleware.js') app.use(mw.authUser({ option1: '1', option2: '2' })) How to mock the middleware using sinon js? I have done in this way but, it throwing me "TypeError: next is not a

passing value from middleware to controller in restify using req.data is not working?

一曲冷凌霜 提交于 2020-06-13 09:07:05
问题 project demo structure middleware auth.js routes user.js controllers userController.js auth.js exports.authUser=(req,res,next)=>{ ... //got user value somehow and it's fine req.user=user; return next(); } user.js (route) server.get("/users",authUser,userController.userList); } userController.js (Controller) exports.userList=(req,res,next)=>{ console.log(req.user); ... } log output is undefined What is the actual way of passing value in restify? tried restify.plugins.pre.context way too. tried

Exports and export assignments are not permitted in module augmentations

岁酱吖の 提交于 2020-06-12 07:19:12
问题 ` import { Request as ExpressRequest, Response as ExpressResponse } from 'express'; declare module 'kvl' { export = kvl; } declare const kvl : { ValidationDone:(param:(error: any, response: ExpressResponse) => void) => void; } ` Exports and export assignments are not permitted in module augmentations. I was declared in .d.ts, Can't I use it like this? 回答1: Module Augmentation: Typescript calls this a module augmentation: You are using an existing module and add new definitions to it. Module

Frequent timeout with app using Serverless Framework (AWS Lambda/Gateway), Express, Mongoose/MongoDB Atlas

早过忘川 提交于 2020-06-12 06:14:13
问题 Trigger warning : Beginner question. I built an api using Express and Mongoose with a MongoDB Atlas DB. Most of the time, it works normally, but often I get timeout errors. This seems to happen very randomly and concerns all routes, etc... Precisely, I get : `502 Internal server error via POSTMAN` and in the Serverless Dashboard, I get : invocation time invoked 1 day ago, mar 08 at 1:38pm fatal error Function execution duration going to exceeded configured timeout limit. cold start duration

express server port configuration issue with pm2 cluster mode

十年热恋 提交于 2020-06-11 20:09:44
问题 Problem: We start pm2 in cluster mode, and pm2 starts as many processes as there are cpu cores, pm2 also tries to start as many node servers as there are cpu cores but the problem here is that it fails to start as many servers because they all try and start on the same port that is 3000, which already gets occupied by the first node server We using nginx and proxy it to 3000 port. we are using pm2 in cluster mode with the following configuration: { "apps" : [{ "script" : "npm", "instances" :

express server port configuration issue with pm2 cluster mode

故事扮演 提交于 2020-06-11 20:07:35
问题 Problem: We start pm2 in cluster mode, and pm2 starts as many processes as there are cpu cores, pm2 also tries to start as many node servers as there are cpu cores but the problem here is that it fails to start as many servers because they all try and start on the same port that is 3000, which already gets occupied by the first node server We using nginx and proxy it to 3000 port. we are using pm2 in cluster mode with the following configuration: { "apps" : [{ "script" : "npm", "instances" :

express server port configuration issue with pm2 cluster mode

岁酱吖の 提交于 2020-06-11 20:06:29
问题 Problem: We start pm2 in cluster mode, and pm2 starts as many processes as there are cpu cores, pm2 also tries to start as many node servers as there are cpu cores but the problem here is that it fails to start as many servers because they all try and start on the same port that is 3000, which already gets occupied by the first node server We using nginx and proxy it to 3000 port. we are using pm2 in cluster mode with the following configuration: { "apps" : [{ "script" : "npm", "instances" :

bulkUpdate in sequelize orm

别来无恙 提交于 2020-06-10 21:18:04
问题 How can we implement bulkUpdate like bulkCreate in sequelize orm, I searched the whole documentation of sequelize but didn't find anything related to bulkUpdate, so I tried to loop update in for loop, it works but is there any other way to update in bulk 回答1: Use the bulkCreate to bulkUpdate method. bulkCreate([...], { updateOnDuplicate: ["name"] }) updateOnDuplicate is an array of fields that will be updated when the primary key (or may be unique key) match the row. Make sure you have at