express

Identity Server 4 for NodeJS API

纵饮孤独 提交于 2020-05-14 06:18:04
问题 I'm trying to figure out how to do the identity server 4 authentication below using NodeJS - way out of my comfort zone here. services.AddAuthentication(IdentityServerAuthenticationDefaults .AuthenticationScheme) .AddIdentityServerAuthentication( options => { options.Authority = "<authority-url>"; options.ApiName = "<api-url>"; }); I'm missing something in the flow here as the C# implementation isn't provided a secret or similar - so the token is probably verified via identity server? How

Identity Server 4 for NodeJS API

▼魔方 西西 提交于 2020-05-14 06:15:15
问题 I'm trying to figure out how to do the identity server 4 authentication below using NodeJS - way out of my comfort zone here. services.AddAuthentication(IdentityServerAuthenticationDefaults .AuthenticationScheme) .AddIdentityServerAuthentication( options => { options.Authority = "<authority-url>"; options.ApiName = "<api-url>"; }); I'm missing something in the flow here as the C# implementation isn't provided a secret or similar - so the token is probably verified via identity server? How

Using mocha/chai to ensure REST API serves up a file?

二次信任 提交于 2020-05-13 14:45:07
问题 I am wanting to validate that a call to one of my REST API's end-point is serving up a file, but I am not sure how to go about it and I am not seeing any examples on this? I did look at the documentation, but this didn't help me much. The server side code essentially does (in Express): handleRetrieveContent(req, res, next) { const filepaht = '...'; res.sendFile(filepath) } and the test case: it('Should get a file', (done) => { chai.request(url) .get('/api/exercise/1?token=' + token) .end

Express: why is this GET request executed twice?

谁说我不能喝 提交于 2020-05-13 14:24:27
问题 I have some code written in Jade, with a link in it. The destination of the link is generated by Jade. When the link is clicked, I notice from my console that the GET-request is being executed twice. Why is this? How can I fix this? Here is my code: Jade file: ul.media-list each paper in paperList div.panel.panel-default div.panel-body li.media div.media-left.media-middle a(href='/publication/view/#{paper.id}') | Some image div.media-body div.btn-group(role='group') //!!! When this link is

Combine sockets and express when using express middleware?

心已入冬 提交于 2020-05-13 06:17:39
问题 Is there a way to get the socket of a request inside of an express middleware? ie: import express from 'express'; import io from 'socket.io'; const app = express(); // combine app and io somehow ... // When client makes a GET request to '/emit/to/self', that client's socket will recieve the 'hello:world' message. app.get('/emit/to/self', (req, res) => { req.socket.emit('hello:world', { ... }); res.send('You just triggered your own socket!') }) The idea being that express middleware has a req

Combine sockets and express when using express middleware?

梦想的初衷 提交于 2020-05-13 06:15:08
问题 Is there a way to get the socket of a request inside of an express middleware? ie: import express from 'express'; import io from 'socket.io'; const app = express(); // combine app and io somehow ... // When client makes a GET request to '/emit/to/self', that client's socket will recieve the 'hello:world' message. app.get('/emit/to/self', (req, res) => { req.socket.emit('hello:world', { ... }); res.send('You just triggered your own socket!') }) The idea being that express middleware has a req

express session not saving for Ipad

泄露秘密 提交于 2020-05-13 05:03:32
问题 I am trying to save a session variable for a user when they login. This works on the computer, but when I try it on an iPad using Safari or Chrome it doesn't save. Here is where I set up my session: app.set('trust proxy', 1) app.use(session({ secret: crypto.randomBytes(20).toString('hex'), resave: false, duration: 60 * 60 * 1000, activeDuration: 10 * 60 * 1000, saveUninitialized: false, cookieName: 'session', cookie: { secure: true } })) I use this route to set up the user: .get('/checkLogin'

express session not saving for Ipad

拜拜、爱过 提交于 2020-05-13 05:00:17
问题 I am trying to save a session variable for a user when they login. This works on the computer, but when I try it on an iPad using Safari or Chrome it doesn't save. Here is where I set up my session: app.set('trust proxy', 1) app.use(session({ secret: crypto.randomBytes(20).toString('hex'), resave: false, duration: 60 * 60 * 1000, activeDuration: 10 * 60 * 1000, saveUninitialized: false, cookieName: 'session', cookie: { secure: true } })) I use this route to set up the user: .get('/checkLogin'

Node.js with Express - throw Error vs next(error)

我与影子孤独终老i 提交于 2020-05-12 11:24:05
问题 Can someone expound on the times when it's appropriate in a node.js Express app to throw an error like so: throw new Error('my error'); or to pass this error on via the callback usually labelled 'next' like so: next(error); and could you please explain what each of them will do in the context of an Express app? for example, here is an express function dealing with URL parameters: app.param('lineup_id', function (req, res, next, lineup_id) { // typically we might sanity check that user_id is

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()