Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* v2: Version 2 Conflicts: .gitignore app.js package.json views/index.jade views/layout.jade
- Loading branch information
Showing
5 changed files
with
51 additions
and
128 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 |
---|---|---|
@@ -1,3 +1 @@ | ||
.DS_Store | ||
node_modules | ||
|
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 |
---|---|---|
@@ -1,95 +1,45 @@ | ||
// include | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var express = require('express'); | ||
var app = module.exports = express.createServer(); | ||
var lessErrorHandler = require ('connect-less-errors'); | ||
var http = require('http'); | ||
var lessMiddleware = require('less-middleware'); | ||
var path = require('path'); | ||
|
||
// configure | ||
app.configure(function() { | ||
var app = express(); | ||
|
||
app.configure(function(){ | ||
app.use(function(req, res, next) { | ||
app.locals.pretty = true; | ||
next(); | ||
}); | ||
app.set('port', process.env.PORT || 3000); | ||
app.set('views', __dirname + '/views'); | ||
app.set('view engine', 'jade'); | ||
app.set('view options', { | ||
pretty: true | ||
}); | ||
app.use(express.favicon()); | ||
app.use(express.logger('dev')); | ||
app.use(express.bodyParser()); | ||
app.use(express.methodOverride()); | ||
app.use(app.router); | ||
lessMiddleware({src: __dirname+'/public/', compress:false, once:false, debug:true }), // set once to false for production | ||
app.use(lessErrorHandler); | ||
app.use(express.static(__dirname + '/public')); | ||
app.use(express.directory(__dirname + '/public')); | ||
app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); | ||
}); | ||
|
||
// routes | ||
/* | ||
app.get('/', function(req, res) { | ||
res.render('index', { | ||
title: 'Simple Server', | ||
watch: { | ||
enabled: watch, | ||
script: '<script src="/socket.io/socket.io.js"></script><script src="/reload.js"></script>' | ||
} | ||
}); | ||
app.use(lessMiddleware({ | ||
src: path.join(__dirname, 'public') | ||
})); | ||
app.use(express.static(path.join(__dirname, 'public'))); | ||
app.use(express.directory(path.join(__dirname, 'public'))); | ||
}); | ||
*/ | ||
|
||
// watch routes | ||
app.get("/reload.js", function (req, res) { | ||
res.writeHead(200, {'Content-Type': 'application/javascript'}); | ||
res.end("var socket = io.connect(); socket.on('file_did_change', function (data) { if (data.file_extension === '.css' || data.file_extension == '.less') { var queryString = '?reload=' + new Date().getTime(); $('link[rel=\"stylesheet\"]').each(function () { if (this.href.indexOf(\"typekit\") === -1) { this.href = this.href.replace(/\\?.*|$/, queryString); } }); } else { window.location.reload(); } });"); | ||
app.configure('development', function(){ | ||
app.use(express.errorHandler()); | ||
}); | ||
|
||
var argv = require('optimist') | ||
.alias('p', 'port') | ||
.describe('p', 'port number') | ||
.boolean('w') | ||
.alias('w', 'watch') | ||
.describe('w', 'watch files for changes and reload').argv, | ||
port = argv.p || 4000, | ||
watch = argv.w || false; | ||
|
||
app.listen(port); | ||
|
||
if (watch) { | ||
var sio = require('socket.io'), | ||
watch = require('watch'), | ||
path = require('path'); | ||
|
||
// use socket.io | ||
var io = sio.listen(app); | ||
io.set('log level', 0); | ||
io.sockets.on('connection', function (socket) { console.log(" -- browser connected."); } ); | ||
|
||
// watch files for changes | ||
watch.createMonitor(__dirname + '/public', { ignoreDotFiles: true}, function (monitor) { | ||
monitor.on("changed", function (f, curr, prev) { | ||
console.log(path.extname(f)); | ||
io.sockets.emit('file_did_change', { | ||
file_extension: path.extname(f) | ||
}); | ||
}); | ||
monitor.on("removed", function (f, stat) { | ||
io.sockets.emit('file_did_change', { | ||
file_extension: path.extname(f) | ||
}); | ||
}); | ||
app.get("/", function (req, res) { | ||
res.render("index", { | ||
title : "Title" | ||
}); | ||
watch.createMonitor(__dirname + '/views', { ignoreDotFiles: true}, function (monitor) { | ||
monitor.on("changed", function (f, curr, prev) { | ||
io.sockets.emit('file_did_change', { | ||
file_extension: path.extname(f) | ||
}); | ||
}); | ||
monitor.on("removed", function (f, stat) { | ||
io.sockets.emit('file_did_change', { | ||
file_extension: path.extname(f) | ||
}); | ||
}); | ||
}); | ||
|
||
// tell people about it | ||
console.log("Socket.io will annouce file changes"); | ||
} | ||
}); | ||
|
||
console.log("Express server listening on port %d in %s mode", port, app.settings.env); | ||
http.createServer(app).listen(app.get('port'), function(){ | ||
console.log("Express server listening on port " + app.get('port')); | ||
}); |
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 |
---|---|---|
@@ -1,16 +1,13 @@ | ||
{ | ||
"name": "simple-express-server", | ||
"version" : "1.3.0", | ||
"name": "application-name", | ||
"version": "0.0.1", | ||
"private": true, | ||
"scripts": { | ||
"start": "node app" | ||
}, | ||
"dependencies": { | ||
"jade": ">= 0.0.1", | ||
"connect-less-errors": ">= 0.1.1", | ||
"watch": ">= 0.5.1", | ||
"socket.io": ">= 0.9.6", | ||
"optimist": ">= 0.3.1", | ||
"express": "2.x", | ||
"less": "*", | ||
"less-middleware": "*", | ||
"zlib": "~1.0.5" | ||
"express": "3.0.3", | ||
"jade": "*", | ||
"less-middleware": "~0.1.11" | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1 +1,5 @@ | ||
h1 Simple Server | ||
extends layout | ||
|
||
block content | ||
h1= title | ||
p Welcome to #{title} |
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 |
---|---|---|
@@ -1,33 +1,7 @@ | ||
!!! 5 | ||
//if lt IE 7 | ||
<html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> | ||
//if IE 7 | ||
<html class="no-js lt-ie9 lt-ie8" lang="en"> | ||
//if IE 8 | ||
<html class="no-js lt-ie9" lang="en"> | ||
//[if gt IE 8]><! | ||
html(class='no-js', lang='en') | ||
//<![endif] | ||
doctype 5 | ||
html | ||
head | ||
meta(charset='utf-8') | ||
meta(http-equiv='X-UA-Compatible', content='IE=edge,chrome=1') | ||
|
||
- if ('undefined' !== typeof title) | ||
title #{title} - Simple Server | ||
- else | ||
title Simple Server | ||
|
||
meta(name='description', content='') | ||
meta(name='viewport', content='width=device-width') | ||
|
||
-if (watch.enabled) | ||
!=watch.script | ||
|
||
body!= body | ||
|
||
script(src='//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js') | ||
script window.jQuery || document.write('<script src="js/libs/jquery-1.7.1.min.js"><\\/script>') | ||
//if lt IE 7 | ||
script(src='//ajax.googleapis.com/ajax/libs/chrome-frame/1.0.3/CFInstall.min.js', defer) | ||
script(defer) window.attachEvent('onload',function(){CFInstall.check({mode:'overlay'})}) | ||
title= title | ||
link(rel='stylesheet', href='/css/style.css') | ||
body | ||
block content |