express

Unable to Split Routes into Separate Files in Express 4.0

元气小坏坏 提交于 2020-01-14 03:04:48
问题 I'm trying to redirect all my routes ending with /api to a manager.js which will then route it to /me . So, a fully qualified request to /me should look like /api/me . Splitting routes up into separate files was easy in Express 3.x, but I'm having trouble in 4.0. app.js app.use('/api',require('./routes/manager')); manager.js var express = require('express'); var manager = express.Router(); module.exports = function() { manager.use('/me',require('../routes/me')); }; me.js var express = require

ExpressJS doesn't fires next routes in app.use

眉间皱痕 提交于 2020-01-14 02:35:08
问题 I have a problem that ExpressJS fires wrong routes while using app.use This is the code from index.js file, where i combine all routes: const app = express(), Router = express.Router(); app.use("/api/vehicle", vehiclesRoutes(Router)); app.use("/api/static-costs", staticCostsRoutes(Router)); app.use("/api/company", companiesRoutes(Router)); app.use("/api/worker", workersRoutes(Router)); Each of this functions (vehiclesRoutes, staticCostsRoutes etc.) are constructed the same. For example

Why doesn't express redirect properly when I edit the status code

断了今生、忘了曾经 提交于 2020-01-13 20:42:13
问题 The standard res.redirect('/some/path'); behaves as expected and immediately redirects the request to /some/path , but if I add a status code, e.g., res.redirect(401, '/some/path') and I navigate to the redirecting page, express doesn't redirect to /some/path , instead I just get the following page: <p>Unauthorized. Redirecting to <a href="/some/path">/</a></p> and it never redirects. This is the same for any status code I supply just by the way. Why doesn't a code specified redirect work as

Can I render multiple sources in EJS

我只是一个虾纸丫 提交于 2020-01-13 19:41:07
问题 I am attempting to use data from 2 different sources, but render them on the same HTML page using EJS, JS and node. This is what I am trying.. app.set('view engine', 'ejs'); app.get('/', function(req, res) { res.render('index.ejs', { data: JSONdata }) res.render('index.ejs', {data2: arrayData}) }); data is a JSON, data2 is an array. I have attempted to look up proper syntax for this exact process but cant seem to find anything. Many thanks. 回答1: You cannot render more than once to a single

Randomly failing tests jest and supertest Node.js

会有一股神秘感。 提交于 2020-01-13 19:28:48
问题 so long story short I'm developing RESTapi that takes a movie title on POST request to the /movies route, fetches info about that movie from external api and saves that object to the database. On POST /comments you add a comment to the different collection but every comment has a 'movie_id' property that has an associated movie. That's my first bigger project so I'm trying to write integrational tests. Everything is great, at least in my opinion, except 3 weird test cases that are failing

How to make proxy revalidate resource from origin

谁说我不能喝 提交于 2020-01-13 18:59:08
问题 I have an Nginx reverse proxy on the same machine as my origin server. I want the proxy to cache dynamic content from the origin, but when a client revalidates a resource, I want the proxy to revalidate with the origin too, and not just return a 304 to the client without checking the origin. For example if I set max-age to 60 seconds, the proxy will happily return 304 for that period without ever checking the origin. I've set up a test where the origin generates a new etag every second, like

Integrating Ember with Express JS

时光毁灭记忆、已成空白 提交于 2020-01-13 17:48:07
问题 I am aiming to build a project using the Express.Js engine and ember.js for the MVC structure. I would like to know if anyone has any tips, or links to resources that can help me with setting up the file structure and how to integrate routing with the MVC. 回答1: We are using ember/express/node backed by riak, and in our solution the ember.js app will be talking to the express REST server. We're using this: https://github.com/nathanaschbacher/chinood Basically the ember app downloads once and

How to implement pagination in nodejs + postgresql

陌路散爱 提交于 2020-01-13 10:22:48
问题 I am novice in Node.js. I want to implement pagination in my Api writing in Node.js using express as a framework and Postgresql as database. I want to get the data in form of pagination. Thanks in advance. 回答1: You can use LIMIT and OFFSET in order to get chunks of data from the database. You need 2 variables to do the pagination, page and itemsPerPage. You'd get the page variable from the route itself, for example /api/items/:page, and for the itemsPerPage, you can make it default 20 items

How to implement pagination in nodejs + postgresql

依然范特西╮ 提交于 2020-01-13 10:22:29
问题 I am novice in Node.js. I want to implement pagination in my Api writing in Node.js using express as a framework and Postgresql as database. I want to get the data in form of pagination. Thanks in advance. 回答1: You can use LIMIT and OFFSET in order to get chunks of data from the database. You need 2 variables to do the pagination, page and itemsPerPage. You'd get the page variable from the route itself, for example /api/items/:page, and for the itemsPerPage, you can make it default 20 items

node.js express.js object is not a function call_non_function

爷,独闯天下 提交于 2020-01-13 10:06:32
问题 I have this error: TypeError: object is not a function at Object.CALL_NON_FUNCTION (native) For this line: var app=express(); I tryed to install express/connect again, but.. nothing. Thanks! EDIT I'm express 2.5.8. my code: error: var http=require('http'); var app=express(); var server=http.createServer(app); (i forget why i need to use this code, i think for cookie handshake works. I have resole the probleme (hanskake cookie) editing manager.js, so i dont need to use this code. But can be