express

Express handling URIError: Failed to decode param

余生颓废 提交于 2020-01-24 10:01:48
问题 var express = require('express'); var app = express(); app.get('*', function (req, res) { var host = req.get('Host'); return res.redirect(['https://', host, req.url].join('')); }); var server = app.listen(8080, function () { console.log('starting'); }); I have a simple script that redirects http to https. This is working fine except when there is a malformed url for example: website.com/%c0%ae%c0%ae. It displays something like: URIError: Failed to decode param '/%c0%ae%c0%ae' at

Express handling URIError: Failed to decode param

爱⌒轻易说出口 提交于 2020-01-24 10:01:44
问题 var express = require('express'); var app = express(); app.get('*', function (req, res) { var host = req.get('Host'); return res.redirect(['https://', host, req.url].join('')); }); var server = app.listen(8080, function () { console.log('starting'); }); I have a simple script that redirects http to https. This is working fine except when there is a malformed url for example: website.com/%c0%ae%c0%ae. It displays something like: URIError: Failed to decode param '/%c0%ae%c0%ae' at

How to use $ref in swagger file properly while working with swagger-ui-express and swagger-jsdoc

瘦欲@ 提交于 2020-01-24 06:01:11
问题 I started to use swagger with swagger-ui-express and swagger-jsdoc to auto document my existing API, which is written with nodejs and express (like described here - example). I came across a problem when I tried to add a $ref to an existing JSON Schema file (that sits inside my project on the same directory as all my js files) on my annotation. My directory looks like this I tried to write the local path ( ./schema.json ) and the absolute path, tried to use # , using many syntaxes and nothing

Error handling in Node.js + Express using promises

会有一股神秘感。 提交于 2020-01-24 05:28:04
问题 Using Node.js + Express (4) + Mongoose (using promises rather than callbacks), I can’t sort out how to tidy up my error handling. What I've got (rather simplified) is: app.get('/xxx/:id', function(request, response) { Xxx.findById(request.params.id).exec() .then(function(xxx) { if (xxx == null) throw Error('Xxx '+request.params.id+' not found'); response.send('Found xxx '+request.params.id); }) .then(null, function(error) { // promise rejected switch (error.name) { case 'Error': response

PayloadTooLargeError: request entity too large

旧巷老猫 提交于 2020-01-24 05:09:37
问题 I got the following error with bodyParser: PayloadTooLargeError: request entity too large at readStream (/root/server/node_modules/raw-body/index.js:155:17) at getRawBody (/root/server/node_modules/raw-body/index.js:108:12) at read (/root/server/node_modules/body-parser/lib/read.js:77:3) at urlencodedParser (/root/server/node_modules/body-parser/lib/types/urlencoded.js:116:5) at Layer.handle [as handle_request] (/root/server/node_modules/express/lib/router/layer.js:95:5) at trim_prefix (/root

fetch: Getting cookies from fetch response

血红的双手。 提交于 2020-01-24 03:44:11
问题 I'm trying to implement client login using fetch on react. I'm using passport for authentication. The reason I'm using fetch and not regular form.submit() , is because I want to be able to recieve error messages from my express server, like: "username or password is wrong" . I know that passport can send back messages using flash messages, but flash requires sessions and I would like to avoid them. This is my code: fetch('/login/local', { method: 'POST', headers: { Accept: 'application/json',

Angular 2 RC with express server instead of lite server

╄→尐↘猪︶ㄣ 提交于 2020-01-23 18:29:29
问题 I would like to create single page application with latest angular 2 rc and express server.I don't know how to link both with out bower,gulp and webpack. There are some starter pack available but can't get the expected one.Please guide me 回答1: The question is really broad but here's a github starter projects link with express and rc.1: Angular 2 starter project with express The server identifies index.html from app.use( express.static(__dirname + '/client' ) ); line. This means look for a

Why multipart is not generating close events

a 夏天 提交于 2020-01-23 17:49:07
问题 Hi I won't to handle upload stream by myself without touching a disk drive. So, the natural selection for me was multiparty module. I took the general example and according the instruction from page https://npmjs.org/package/multiparty I changed form.parse to non callback request. In that case the disk won't be touched. My code looks like this: multiparty = require("multiparty") http = require("http") util = require("util") # show a file upload form http.createServer((req, res) -> if req.url

How is req and res accessible accross modules in Express.js

僤鯓⒐⒋嵵緔 提交于 2020-01-23 11:58:20
问题 While using express.js for handling various routes I want to encapsulate all of my route code in a seperate module, but how can I access the req and res object across modules, See the code below The main file examples.js is written as follows var app = require('express').createServer(); var login = require('./login.js'); app.get('/login', login.auth(app.req, app.res)); app.listen(80); What I want is that the login handling code be written in a seperate module/file called login.js, the

Getting express.js to show a public folder

跟風遠走 提交于 2020-01-23 09:57:33
问题 I've recently built a quick one page app using express.js, and this is really my first js framework (actually, my first js project, so I'm really new to this). I've got a subscription to the new typography.com cloud fonts, and I'm having trouble locating the "fonts" folder that I place in the public folder. Is there a way I need to add the folder and specify a route? Here's my app.js file: /** * Module dependencies. */ var express = require('express'), routes = require('./routes'), user =