forked from chevcast/U413-archived
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified connection string to point to a local mongodb instance inste…
…ad of the u413 public development database. It's being retired.
- Loading branch information
Alex Ford
authored and
Alex Ford
committed
Apr 30, 2014
1 parent
b8a8295
commit c79d61f
Showing
1 changed file
with
61 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,76 +21,72 @@ var simpledb = require('mongoose-simpledb'), | |
require('./utilities/prototypeHelpers')(); | ||
|
||
// Get connection string. | ||
var connString = process.env.CONNECTION_STRING; | ||
if (!connString) connString = 'mongodb://u413-dev:[email protected]:27758/u413-dev'; | ||
var connectionString = process.env.CONNECTION_STRING || 'mongodb://localhost/u413'; | ||
|
||
// Initialize the database module. | ||
simpledb.init( | ||
{ connectionString: connString }, | ||
function (err, db) { | ||
if (err) return console.error(err); | ||
// Initialize node-static, a static file serving module. | ||
var file = new nodeStatic.Server('./public'), | ||
port = process.env.PORT || 3000; | ||
// Create basic http server. | ||
var server = http.createServer(function (request, response) { | ||
// Add a helper function to the response for easy redirections. | ||
response.redirect = function (url) { | ||
response.writeHead(301, { 'location': url }); | ||
response.end(); | ||
}; | ||
simpledb.init(connectionString, function (err, db) { | ||
if (err) return console.error(err); | ||
// Initialize node-static, a static file serving module. | ||
var file = new nodeStatic.Server('./public'), | ||
port = process.env.PORT || 3000; | ||
// Create basic http server. | ||
var server = http.createServer(function (request, response) { | ||
// Add a helper function to the response for easy redirections. | ||
response.redirect = function (url) { | ||
response.writeHead(301, { 'location': url }); | ||
response.end(); | ||
}; | ||
|
||
// If the request is for "www." then redirect to bare domain. | ||
if (request.url.match(/^www/)) { | ||
response.writeHead(301, { 'location': redirect }); | ||
} | ||
// If the request is for "www." then redirect to bare domain. | ||
if (request.url.match(/^www/)) { | ||
response.writeHead(301, { 'location': redirect }); | ||
} | ||
|
||
// When the request is finished, serve files. | ||
request.addListener('end', function () { | ||
// If the request is for the root URL then compile the index Jade view and serve it... | ||
if (request.url === '/') { | ||
var jadeFn = jade.compile( | ||
fs.readFileSync(path.resolve('views', 'index.jade')), | ||
{ filename: path.resolve('views', 'index.jade') } | ||
); | ||
response.writeHead(200, { "Content-Type": "text/html" }); | ||
response.end(jadeFn()); | ||
} | ||
else if (request.url === '/styles.css') { | ||
var stylusFile = fs.readFileSync(path.resolve('public', 'styles.styl')); | ||
stylus(stylusFile.toString()).render(function(err, css) { | ||
if (err) return console.error(err); | ||
response.writeHead(200, { "Content-Type": "text/css" }); | ||
response.end(css); | ||
}); | ||
} | ||
// ...otherwise let node-static match the request to static files in the "public" directory. | ||
else | ||
file.serve(request, response); | ||
}).resume(); | ||
}).listen(port, function () { | ||
console.log("Listening at http://localhost:%s", port); | ||
}); | ||
// When the request is finished, serve files. | ||
request.addListener('end', function () { | ||
// If the request is for the root URL then compile the index Jade view and serve it... | ||
if (request.url === '/') { | ||
var jadeFn = jade.compile( | ||
fs.readFileSync(path.resolve('views', 'index.jade')), | ||
{ filename: path.resolve('views', 'index.jade') } | ||
); | ||
response.writeHead(200, { "Content-Type": "text/html" }); | ||
response.end(jadeFn()); | ||
} | ||
else if (request.url === '/styles.css') { | ||
var stylusFile = fs.readFileSync(path.resolve('public', 'styles.styl')); | ||
stylus(stylusFile.toString()).render(function(err, css) { | ||
if (err) return console.error(err); | ||
response.writeHead(200, { "Content-Type": "text/css" }); | ||
response.end(css); | ||
}); | ||
} | ||
// ...otherwise let node-static match the request to static files in the "public" directory. | ||
else | ||
file.serve(request, response); | ||
}).resume(); | ||
}).listen(port, function () { | ||
console.log("Listening at http://localhost:%s", port); | ||
}); | ||
|
||
// Configure shotgun and shotgun-client modules. | ||
var shotgun = require('shotgun'), | ||
shell = new shotgun.Shell({ | ||
debug: process.env.DEBUG, | ||
// Rather than define access functions on each command module we will specify the default access for all | ||
// command modules on the shell and set them to the shell helper function we created for checking command access. | ||
defaultCmdAccess: function (shell, cmdName) { | ||
return shell.canAccessCmd(cmdName); | ||
} | ||
}), | ||
shotgunClient = require('shotgun-client'); | ||
// Configure shotgun and shotgun-client modules. | ||
var shotgun = require('shotgun'), | ||
shell = new shotgun.Shell({ | ||
debug: process.env.DEBUG, | ||
// Rather than define access functions on each command module we will specify the default access for all | ||
// command modules on the shell and set them to the shell helper function we created for checking command access. | ||
defaultCmdAccess: function (shell, cmdName) { | ||
return shell.canAccessCmd(cmdName); | ||
} | ||
}), | ||
shotgunClient = require('shotgun-client'); | ||
|
||
// Attach custom functions to the shell so they can be used in our command modules for U413. | ||
extend(shell, shellFunctions); | ||
shell.db = db; | ||
// Attach custom functions to the shell so they can be used in our command modules for U413. | ||
extend(shell, shellFunctions); | ||
shell.db = db; | ||
|
||
// Attach shotgun-client to the http server so it can listen for connections. | ||
shotgunClient.attach(server, shell); | ||
// Attach shotgun-client to the http server so it can listen for connections. | ||
shotgunClient.attach(server, shell); | ||
|
||
shell.io.set('transports', ['xhr-polling']); | ||
} | ||
); | ||
shell.io.set('transports', ['xhr-polling']); | ||
}); |