Skip to content
Browse files

Move over examples from connect that apply to spark.

  • Loading branch information...
1 parent e8baaf1 commit d44147973689a2f50649850194327185629afc54 @creationix creationix committed Jul 16, 2010
View
24 examples/config/app.js
@@ -0,0 +1,24 @@
+
+/**
+ * Module dependencies.
+ */
+
+var http = require('http');
+
+/**
+ * `$ connect --chdir examples/config`
+ * will auto-detect ./config.js and apply it.
+ *
+ * `$ connect --config path/to/config examples/config.app`
+ * will load the app relative to CWD, and the given config module.
+ *
+ * NOTE: you can use --config several times to apply different configurations
+ * if needed.
+ */
+
+module.exports = http.createServer(function(req, res){
+ res.writeHead(200, {
+ 'Content-Type': 'text/plain'
+ });
+ res.end('Wahoo');
+});
View
10 examples/config/config.js
@@ -0,0 +1,10 @@
+
+module.exports = {
+ env: 'production',
+ port: 4321,
+ host: '127.0.0.1',
+ verbose: true,
+ 'no-color': true,
+ eval: ['require("sys").puts("anything you want!")',
+ 'require("sys").puts("or use an array for several flags")']
+}
View
4 examples/custom-config/config/development.js
@@ -0,0 +1,4 @@
+module.exports = {
+ host: 'localhost',
+ port: 3000
+};
View
3 examples/custom-config/config/production.js
@@ -0,0 +1,3 @@
+module.exports = {
+ port: 80
+};
View
23 examples/custom-config/server.js
@@ -0,0 +1,23 @@
+
+/**
+ * Module dependencies.
+ */
+
+var sys = require('sys'),
+ Connect = require('./../../lib/connect');
+
+// Based on the current env name require / mixin the
+// additional file-based configuration. Try using
+// --env production
+
+var conf = require('./config/' + process.connectEnv.name);
+for (var key in conf) {
+ process.connectEnv[key] = conf[key];
+}
+
+sys.log('loading config file "config/' + process.connectEnv.name + '.js"');
+
+module.exports = Connect.createServer(function(req, res, next){
+ res.writeHead(200, { 'Content-Type': 'text/plain' });
+ res.end(sys.inspect(process.connectEnv));
+});
View
9 examples/hello-world/app.js
@@ -0,0 +1,9 @@
+// Note that even though this looks like a normal node http app, it's really a
+// valid connect app using the connect middleware stack.
+
+var Connect = require('../../lib/connect');
+
+module.exports = Connect.createServer(function(req, res) {
+ res.writeHead(200, { 'Content-Type': 'text/plain' });
+ res.end('Hello World');
+});
View
3 examples/hello-world/run.js
@@ -0,0 +1,3 @@
+#!/usr/bin/env node
+
+require('./app').listen(8080);
View
11 examples/node/app.js
@@ -0,0 +1,11 @@
+
+/**
+ * Module dependencies.
+ */
+
+var http = require('http');
+
+module.exports = require('http').createServer(function(req, res){
+ res.writeHead(200, { 'Content-Type': 'text/plain' });
+ res.end(this.env.name);
+});
View
2 examples/ssl/.gitignore
@@ -0,0 +1,2 @@
+*.pem
+*.csr
View
7 examples/ssl/app.js
@@ -0,0 +1,7 @@
+var Connect = require('../../lib/connect');
+
+module.exports = Connect.createServer(function(req, res) {
+ res.writeHead(200, { 'Content-Type': 'text/plain' });
+ var secure = req.socket.secure;
+ res.end('secure=' + secure + ', that is ' + (secure ? 'good' : 'bad'));
+});
View
7 examples/ssl/genkeycert.sh
@@ -0,0 +1,7 @@
+#!/bin/sh -e
+
+# http://www.silassewell.com/blog/2010/06/03/node-js-https-ssl-server-example/
+
+openssl genrsa -out privatekey.pem 1024
+openssl req -new -key privatekey.pem -out certrequest.csr
+openssl x509 -req -in certrequest.csr -signkey privatekey.pem -out certificate.pem
View
21 examples/ssl/start.js
@@ -0,0 +1,21 @@
+#!/usr/bin/env node
+/**
+ * Demonstrates enabling SSL on the nodejs http.Server when starting
+ * Connect from JavaScript.
+ */
+
+var crypto = require('crypto');
+var fs = require('fs');
+
+var app = require('./app');
+app.env = { host: '*',
+ port: 3000
+ };
+
+var creds = crypto.createCredentials(
+ { key: fs.readFileSync('privatekey.pem', 'ascii'),
+ cert: fs.readFileSync('certificate.pem', 'ascii')
+ });
+app.setSecure(creds);
+
+app.listen();
View
8 examples/ssl/start.sh
@@ -0,0 +1,8 @@
+#!/bin/sh -e
+#
+# Use ./genkeycert.sh before running!
+#
+# Demonstrates usage of SSL support in the connect(1) binary.
+#
+
+../../bin/connect --ssl-key privatekey.pem --ssl-crt certificate.pem
View
16 examples/tcp/server.js
@@ -0,0 +1,16 @@
+
+/**
+ * Module dependencies.
+ */
+
+var net = require('net'),
+ sys = require('sys');
+
+module.exports = net.createServer(function(stream){
+ stream.addListener('data', function(chunk){
+ stream.write(chunk);
+ });
+ stream.addListener('end', function(){
+ stream.end();
+ });
+});

0 comments on commit d441479

Please sign in to comment.
Something went wrong with that request. Please try again.