senchalabs / connect Goto Github PK
View Code? Open in Web Editor NEWConnect is a middleware layer for Node.js
License: MIT License
Connect is a middleware layer for Node.js
License: MIT License
grab *.sass and auto-render
hi, this is a really dumbass question, but in one of the examples, it does require('sass'), meaning that you've install sass to a path that node can see. Q is - how do u do this from the github project ? cheers J
The mkdirs() function doesn't handle absolute paths because it splits on "/" and then tries to create each level. This fails because the first element of the array is the empty string.
Only seems to happen when using the "workers" switch (haven't looked into that).
To Reproduce:
connect --pidfile /var/run/connect.pid --workers 1
Result:
Error: ENOENT, No such file or directory ''
at Object.mkdirSync (fs:272:18)
at mkdirs (/usr/local/bin/connect:129:16)
at start (/usr/local/bin/connect:396:16)
at parseArguments (/usr/local/bin/connect:565:13)
at Object.<anonymous> (/usr/local/bin/connect:581:29)
in session memory store. what does that do beyond +new Date - ms
?
With the following options:
-I, --include
-e, --eval
-E, --env
-H, --host
-p, --port
-l, --log
-D, --daemonize
-P, --pid
-u, --user
-g, --group
-c, --chdir,
-h, --help
--version
Currently they dont work with the static middleware, however this would be nice so that we can keep things DRY with http caching etc
The redirect filter puts the redirect function on the response object but the documentation indicates that the method is added to the request object:
http://extjs.github.com/Connect/redirect.html
i'm not sure if this is a nodejs problem or a connect issue or something i'm doing wrong. i've hacked a Ext.Direct handler based on the JsonRpc middleware and it works as expected when called from Chrome and IE, but for some reason the redirect middleware is returning a 404 to FF.
my code looks like this:
var Connect = require('./../lib/connect');
var root = __dirname + "/public";
// Create a server with no initial setup
var Server = module.exports = Connect.createServer();
// Add global filters
Server.use("/",
Connect.responseTime()
//Connect.logger({ format: ':method :url :response-time' })
);
// Serve dynamic responses
Server.use("/direct",
Connect.direct(company)
);
// Serve static resources
Server.use("/",
Connect.staticProvider(root)
);
the Chrome headers (captured via Fiddler) look like this:
POST http://vmubuntu03:3000/direct HTTP/1.1 Host: vmubuntu03:3000 Connection: keep-alive User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.70 Safari/533.4 Referer: http://vmubuntu03:3000/array-grid.html Content-Length: 71 Cache-Control: max-age=0 Origin: http://vmubuntu03:3000 X-Requested-With: XMLHttpRequest Content-Type: application/json Accept: */* Accept-Encoding: gzip,deflate Accept-Language: en-US,en;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 {"action":"Company","method":"getAll","data":null,"type":"rpc","tid":2}
the IE headers (captured via Fiddler) look like this:
POST http://vmubuntu03:3000/direct HTTP/1.1 Accept: */* Accept-Language: en-us Referer: http://vmubuntu03:3000/array-grid.html x-requested-with: XMLHttpRequest Content-Type: application/json Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; GTB6.5; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MDDC) Host: vmubuntu03:3000 Content-Length: 71 Connection: Keep-Alive Pragma: no-cache {"action":"Company","method":"getAll","data":null,"type":"rpc","tid":2}
the FF headers (captured via Fiddler) look like this:
POST http://vmubuntu03:3000/direct HTTP/1.1 Host: vmubuntu03:3000 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.4) Gecko/20100611 Firefox/3.6.4 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 115 Connection: keep-alive Content-Type: application/json; charset=UTF-8 X-Requested-With: XMLHttpRequest Referer: http://vmubuntu03:3000/array-grid.html Content-Length: 71 Pragma: no-cache Cache-Control: no-cache {"action":"Company","method":"getAll","data":null,"type":"rpc","tid":2}
any ideas/suggestions?
ala express
Currently if you do: connect test-server.js, you'll get an error saying that file extensions in module names is now unsupported.
Would it make sense for connect to automatically trim .js from the argv[0] ?
I'm trying to write a middleware that looks at the extension of the requested page, strips it from the requested URL, and adds a 'format' property matching the mime-type of the extension. But no matter what, the URL gets set back to what it was before.
Even if I pass a new request object (with next
) the URL still cannot be changed.
This seems like important functionality to give to middlewares.
This seems to happen because of line 223 in index.js. I'm not sure what the best solution is, but I think it is probably not to have any routing happening at all in Connect but relegate it to middlewares. That would certainly be more rack like. Either that or before line 223 do a check to see if you are dealing with the same URL and if not don't set it.
on the site, in the "Middleware Authoring" section it has the following line in the first example:
res.writeHead(200, { 'Content-Type: 'text/plain' });
It is missing an apostrophe. Corrected:
res.writeHead(200, { 'Content-Type': 'text/plain' });
I don't know if things like this are really worth a bug report, would a message with a patch be more useful?
Hi,
Using router middleware, I can only extract params from a query string by parsing req:
app.get('/search', function(req, res){
var q = require('url').parse(req.url, true)['query']['q'];
res.simpleBody('200', q);
});
is it normal? I think it would be pretty good to add functionality making this process easier.
And also a method to check is it ajax request or not.
Thanks.
Okay, so, looking at the examples, there seems to be some repetition in them for certain things, wouldn't it be good if we could group things together into a scope, to stop that repetition?
Example:
var controlled = ["/console/", "/files/", "/messages/"];
module.exports = require('./lib/connect').createServer([
// We want to log all http traffic
{filter: "log"},
// Scope the following only if the route is controlled.
{filter: "scope", routes: controlled, segments: [
// Add cookie based sessions to the controlled routes
{filter: "session"},
// Make sure the user is authenticated
{filter: "authentication", param: {}},
// Restrict access to controlled pages by user rules
{filter: "authorization", param: {}}
]},
// Listen for publish subscribe messages in real-time
{provider: "pubsub", route: "/messages/", param: {}},
// This is a logic endpoint, it's ext-direct rpc protocol
{provider: "direct", route: "/console/", param: {}},
// Use conditional GET to save on bandwidth
{filter: "conditional-get"},
// Cache all rest and static responses
{filter: "cache"},
// Gzip all resources when it makes sense
{filter: "gzip"},
// This is another logic endpoint, it's a rest-style interface to files
// {provider: "rest", route: "/files/", param: {}},
// Finally serve everything else as static files
{provider: "static", root: __dirname + "/public"},
// Show pretty pages for exceptions
{filter: "error-handler"}
]);
we need to save the pids out
only body-decoder is there right now, need some time to finish docs
could potentially just push the generated routes as middleware onto the stack so we can next()
not sure if i'm doing something wrong but running the jsonrpc app and calling it with the sample call crashes, but not always on the first call. sometimes the first call returns:
{"error":{"code":-32700,"message":"Parse Error."},"id":null,"jsonrpc":"2.0"}
for:
curl -H "Content-Type: application/json" -d "{ "jsonrpc": "2.0", "method": "add", "params": [1,2], "id":2 }" http://localhost:3000
but the second call will always then crash at:
/home/cginzel/Connect/examples/jsonrpc/lib/connect/providers/jsonrpc.js:88 return respond(normalize(rpc, { error: { code: PARSE_ERROR }}) ^ ReferenceError: PARSE_ERROR is not defined at IncomingMessage. (/home/cginzel/Connect/examples/jsonrpc/lib/connect/providers/jsonrpc.js:88:17) at IncomingMessage.emit (events:25:26) at HTTPParser.onMessageComplete (http:110:23) at Stream.ondata (http:747:22) at IOWatcher.callback (net:502:31) at node.js:221:9
Would be cool to do:
Connect.vhost('hostname', http.createServer(...))
to know where you are at
stderr is blocking AFAIK in node, plus I think some people (myself included) would rather specify an error log. This could be derived from --logfile
currently if you export a Server, and include it within
another Server and pass a custom environment object to the first,
the second will not receive this object.
We should probably pass them down and merge custom environment objects along the way
yes? no? brain storming
I had the following fatal error whilst running the 'error' example
/Users/jonahfox/src/Connect/lib/connect/index.js:211 if (e instanceof assert.AssertionError) { ^ ReferenceError: assert is not defined at next (/Users/jonahfox/src/Connect/lib/connect/index.js:211:13) at Server.handle (/Users/jonahfox/src/Connect/lib/connect/index.js:218:5) at Server.emit (events:32:26) at HTTPParser.onIncoming (http:815:10) at HTTPParser.onHeadersComplete (http:88:31) at Stream.ondata (http:747:22) at IOWatcher.callback (net:502:31) at node.js:221:9
This is 0.1.98 on OSX Leopard.
sounds a bit funny but makes more sense
Since the switch-round, I get a blank page in Firefox.
Maybe it's that I'm new, or maybe I'm an idiot, but I can't figure out how to use it.
I'm confused as to what the "route" function is in a layer. I don't see it documented; what is its signature and what is it meant to do?
(Also, is the documentation at http://extjs.github.com/Connect/ tested? I see the following in the "Middleware" section:
module.exports = connect.createServer(
connect.logger(),
connect.static(__dirname + '/public)
);
which seems to have an invalid reference (static
instead of staticProvider
) and an unclosed string literal.)
double the markdown as site usage docs / man
from docs
-n, --workers NUM Number of worker processes to spawn
Once we get going I will add some benchmarking
scripts similar to Express for our blogging
When using the staticProvider
middleware, a get request like:
GET /path%20with%20space.html
will choke the middleware. A simple one line fix in the staticProvider.js file does the trick:
filename = Path.join(root, decodeURIComponent(pathname));
decodeURIComponent
(or I remember a better node equivalent was committed a while back) needs to be called to remove encoded URI chars from the path, that way spaces, etc. will work again.
I think the implementation of pubsub.js could use a patch. It seems it uses remoteAddress and remotePort to generate the subscriber ID, but I think when using long polling, this will result in a different subscriber ID each time, no? I think a better way would be to use the session ID. When debugging through the code without this type of patch, it seems like you will get a new subscriber each time. Pretty simple fix and it works when there is no session in original way.
Change this line:
var id = req.socket.remoteAddress + req.socket.remotePort;
To:
var id = req.session ? req.session.id : req.socket.remoteAddress + req.socket.remotePort;
any timeline on when we might see some direct provider code hit the project?
Are you planning to add an md5 to stop tampering ?
Unfortunately it seems that JS/CSS inserted before the <html> tag will not work in either FF or Chrome.
Allow charset
Right now you can add other properties to your middleware object, like this:
{
handle: function(req, res, next) { ... },
otherProp: "What's up"
}
But only specific additional properties are allowed. For example, my middleware object cannot have a 'route' property. Ideally, the entire middleware object would be fair game, but at least a list of what keys Connect needs available would be useful...
What do you guys think?
Is there support for websockets or any way to integrate existing websocket solutions like "node-websocket-server"?
node-websocket-server: http://github.com/miksago/node-websocket-server
something seriously weird is going on... not sure if this is related to the other issue, tests all run fine however some cases when an app is running connect.Server#handle()
's req
is undefined
If you visit the following address:
http://127.0.0.1:3000// (double slash at the end)
The url.parse function will return an undefined pathname.
This is a bug in the url.parse function I think, but Connect will always return the 'Cannot find //' page and won't let your middleware handle this.
Add json rpc middleware
There is no /usr/local
directory, and non-sudo install doesn't work either.
Should consider it, but I would rather stay away from this and defer that usage to the user if needed, since it slows things down quite a bit, especially since we dont have native c base64 exposed
note to self, setup CI
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.