routes

What is a better way to authenticate some of the routes on Express 4 Router?

孤街浪徒 提交于 2019-12-03 00:48:37
I'm using Express 4 where I have a route protected by passport.js, like this: var media = require('express').Router(); media.get('/', function(req, res) { // provide results from db }); media.post('/', passport.authenticate('bearer'), function(req, res) { // This route is auth protected }); So - get collection routes should (mostly) not be protected for me, and create/update routes should. But this requires me to pass passport to all my route files (I have 7 so far), then to add that as a middleware to some of them. I like the version where you can do something like this: var router = require(

Mongoose one-to-many

一曲冷凌霜 提交于 2019-12-03 00:44:39
can you explain me how to organize mongoose models to create one to many connections? It is needed keep separate collections. suppose i have stores and items //store.js var mongoose = require('mongoose'); module.exports = mongoose.model('Store', { name : String, itemsinstore: [ String] }); //item.js var mongoose = require('mongoose'); module.exports = mongoose.model('Item', { name : String, storeforitem: [String] }); Am i doing it in the right way? And how to access pass data to arryas? Here is the code yo enter name to item. But how to enter id to array of id's (itemsinstore)? app.post('/api

Ending a Rails 2 URL with an IP address causes routing error?

爱⌒轻易说出口 提交于 2019-12-03 00:40:54
I'm trying to construct URLs in the format http://servername/find/by/CRITERION/VALUE CRITERION is a finite set of strings, as is VALUE. Trouble is, VALUE needs to be an IP address in some situations, and it's causing me a routing error. Here's my route: map.find 'find/by/:criterion/:query', :controller => "find", :action => "by" And the error, from the Mongrel logs: Processing ApplicationController#index (for 127.0.0.1 at 2010-05-07 10:20:32) [GET] ActionController::RoutingError (No route matches "/find/by/ip/1.2.3.4" with {:method=>:get}): Rendering rescues/layout (not_found) If I visit /find

Meteor, Iron:Router Passing Multiple Properties on Router.go

和自甴很熟 提交于 2019-12-03 00:07:10
My dilemma is that I would like to pass multiple object properties to an iron:router route in Meteor. The reasoning is that I would like to pass it a property to name my url with and a property to find a collection item with. They are completely independent of each other and I can't use the url property because it is not a value in the collection item. This is what I have: Template.items.events({ 'click': function () { itemName = this.name.replace(/ /g,'') Router.go('itemDetails', {itemName: itemName}) } }); The problem is that although the Router handles this fine and sends me to the correct

Shorten Zend Framework Route Definitions

我是研究僧i 提交于 2019-12-02 23:44:54
How can I shorten the definition of my custom routes in Zend Framework? I currently have this as definition: $route = new Zend_Controller_Router_Route( ":module/:id", array( "controller" => "index", "action" => "index" ), array("id" => "\d+") ); self::$frontController->getRouter()->addRoute('shortcutOne', $route); $route = new Zend_Controller_Router_Route( ":module/:controller/:id", array("action" => "index"), array("id" => "\d+") ); self::$frontController->getRouter()->addRoute('shortcutTwo', $route); $route = new Zend_Controller_Router_Route( ":module/:controller/:action/:id", null, array(

How to dynamically call routes helper in rails?

懵懂的女人 提交于 2019-12-02 23:33:34
For example, I have constructed a string called "new_work_path", now I want to call that helper as a method. I've tried send("new_work_path", vars) and calling the same send from many objects. But I don't think that I've found the right object to call these helpers. To do object.send("new_work_path", vars) , what object should I be looking for? I've tried to look for this online for a while but couldn't find anything. If anyone can shine some lights on this one, it would be great! Thanks! try Rails.application.routes.url_helpers.send(...) Edit: As Larry Gebhardt mentioned the url_helpers

Configuring Express 4.0 routes with socket.io

二次信任 提交于 2019-12-02 22:31:27
I have created a new Express application. It generated app.js for me and I have then created the following index.js bringing in socket.io: var app = require('./app'); server=app.listen(3000); var io = require('socket.io'); var socket = io.listen(server, { log: false }); socket.on('connection', function (client){ console.log('socket connected!'); }); Can anyone advise how I would access socket.io within the routes files? For reference, the default generated app.js is below: var express = require('express'); var path = require('path'); var favicon = require('static-favicon'); var logger =

How to make a URL filter to route actions with Servlets?

孤者浪人 提交于 2019-12-02 21:30:55
I'm currently developing a Java EE web framework and I would want to know how I could route my URL's... I want support HMVC feature! URL's will follow this rule: /module_name/controller_name/action_name, where: module_name: path separated by slashes... Ex.: Submodule "Y" of Module "X": /X/Y controller_name: name of controller with no special chars action_name: name of action with no special chars I would like map /module_name/controller_name/ to a specific servlet controller! Action part is a public method on that class! :) How I could do this? Using filters? I want an example, if possible! i

Want any alphanumeric and underscore, dash and period to pass

ぐ巨炮叔叔 提交于 2019-12-02 21:09:34
问题 In my controller, I current set a constraint that has the following regex: @"\w+" I want to also allow for underscore,dash and period. THe more effecient the better since this is called allot. any tips? 回答1: try this: @"[._\w-]+" 回答2: (?:\w|[-_.])+ Will match either one or more word characters or a hyphen, underscore or period. They are bundled in a non-capturing group. 回答3: Does the following help? @"[\w_-.]+" P.S. I use Rad Software Regular Expression Designer to design complex Regexes. 回答4

What should my Rails routes look like to work with pushState Ember.js routes?

强颜欢笑 提交于 2019-12-02 21:04:31
In short... When building an Ember.js app to persist to a Rails app, how should I handle Rails routing/views? I would think I just need Rails to render the application.html.erb layout so the Ember.js app initializes and handles the routing/view/templates. Details: Specifically if I visit localhost:3000 , before my Ember.js app has a chance to initialize, Rails hits the "index" action on the projects controller. It will complain about a missing index template. I have no index.html.erb view as my Ember.js app has a view/template for it. Should I be creating blank views for the Rails app? Should