express

CORS Error: “requests are only supported for protocol schemes: http…” etc

懵懂的女人 提交于 2020-01-30 13:10:28
问题 I am trying to a simple application. I have an Express backend which, returns a JSON string when visited at localhost:4201/ticker . When I run the server and, make a request to this link from my Angular Service over http , I get the following error: XMLHttpRequest cannot load localhost:4201/ticker. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https. I read the following article: Understanding and Using CORS and, as stated, used the cors

Need advice to design database in mongodb with mongoose

依然范特西╮ 提交于 2020-01-30 11:45:46
问题 I have 2 collections: Hospital and Patient. This month the patient is examination at hospital A, But next month, this patient is examination at hospital B. So when updating patient information, how to save patient's history that patient is already examination at hospital A? Please give me an advice? Thanks 回答1: You need to have a separate examination collection for this. (It is like the intermediate (associative) table in relational databases.) One way to solve this is using virtual populate.

Need advice to design database in mongodb with mongoose

家住魔仙堡 提交于 2020-01-30 11:45:09
问题 I have 2 collections: Hospital and Patient. This month the patient is examination at hospital A, But next month, this patient is examination at hospital B. So when updating patient information, how to save patient's history that patient is already examination at hospital A? Please give me an advice? Thanks 回答1: You need to have a separate examination collection for this. (It is like the intermediate (associative) table in relational databases.) One way to solve this is using virtual populate.

Always getting invalid signature in jwt.io

耗尽温柔 提交于 2020-01-30 06:12:07
问题 I always get invalid signature when I input the generated token in jwt.io Here is my code for making the token const secret = 'secret'; const token = jwt.sign({ username: user.username, userID: user._id }, secret, { expiresIn: "1hr" } ); What did I do wrong? I'm using the jsonwebtoken package. https://github.com/auth0/node-jsonwebtoken 回答1: If you are using jsonwebtoken lib, I tried and able to create the token and verify as well. Please have a look at the code and let me know in comments if

express 4.x redirect http to https

人盡茶涼 提交于 2020-01-28 04:29:21
问题 i have the following code : var https = require('https'); var http = require('http'); var express = require('express'); var app = express(); var router = express.Router(); app.use('/', router); //listen server on https var server = https.createServer(config.sslCredential, app); server.listen(config.serverPort); //listen server on http, and always redirect to https var httpServer = http.createServer(function(req,res){ res.redirect(config.serverDomain+req.url); }); httpServer.listen(config

How do i stream response in express

烂漫一生 提交于 2020-01-27 23:08:08
问题 I've been trying to get a express app to send the response as stream. var Readable = require('stream').Readable; var rs = Readable(); app.get('/report', function(req,res) { res.statusCode = 200; res.setHeader('Content-type', 'application/csv'); res.setHeader('Access-Control-Allow-Origin', '*'); // Header to force download res.setHeader('Content-disposition', 'attachment; filename=Report.csv'); rs.pipe(res); rs.push("USERID,NAME,FBID,ACCOUNT,SUBSCRIPTION,PRICE,STATE,TIMEPERIOD\n"); for (var i

How does one unit test routes with Express?

不想你离开。 提交于 2020-01-27 08:51:05
问题 I'm in the process of learning Node.js and have been playing around with Express. Really like the framework;however, I'm having trouble figuring out how to write a unit/integration test for a route. Being able to unit test simple modules is easy and have been doing it with Mocha; however, my unit tests with Express fail since the response object I'm passing in doesn't retain the values. Route-Function Under Test (routes/index.js): exports.index = function(req, res){ res.render('index', {

getting CORS error when redirecting with express server [duplicate]

a 夏天 提交于 2020-01-26 03:55:06
问题 This question already has answers here : “No 'Access-Control-Allow-Origin' header present on requested origin” error for res.redirect(“http://www.google.com”) (1 answer) “No 'Access-Control-Allow-Origin' header is present on the requested resource” error for response from http://www.google.com/ (1 answer) Closed 10 days ago . I've enabled cors on my node backend with one endpoint that doesn't return data but redirect to an external url. I'm getting Access to fetch at 'https://google.com/'

Cannot delete from mongodb collection angular MEAN stack

懵懂的女人 提交于 2020-01-25 21:47:27
问题 Im trying to delete a record from my mongodb collection "setlist" in a MEAN stack application. index.html <table class="table"> <thead> <tr> <th>Artist</th> <th>Title</th> <th>Key</th> <th>Action</th> <th> </th> </tr> </thead> <tbody> <tr ng-repeat="setTrack in setlist" ng-click="clicked"> <td><h4>{{setTrack.Artist}}</h4></td> <td><h4>{{setTrack.Title}}</h4></td> <td><h4>{{setTrack.Key}}</h4></td> <td><button class="btn btn-success" ng-click="removeFromSL(setTrack._id)">Remove from set list<

Unexpected Token U Ajax Syntax Error

时光总嘲笑我的痴心妄想 提交于 2020-01-25 21:41:49
问题 I've been having a problem all day sending json data via ajax to Express. My ajax looks like this: $('#saveClause').click(function () { var username = document.getElementById('postUserName').innerHTML; var clauseTitle = document.getElementById('modalTitle').innerHTML; var clauseDescription = document.getElementById('modalDescription').innerHTML; var clauseText = document.getElementById('modalText').innerHTML; $.ajax({ url: "/classes/updateAssignment", type: "post", dataType: "json", data: {