Permalink
Browse files

[server, styles] cdn

  • Loading branch information...
1 parent f308e98 commit 5fa081e003fd9b3dca00278a7aafb02d136ea931 @indutny committed Jun 28, 2011
Showing with 39 additions and 10 deletions.
  1. +4 −0 config.json.sample
  2. +28 −4 lib/slides/server.js
  3. +2 −1 package.json
  4. +3 −3 public/css/page.styl
  5. +2 −2 views/layout.jade
View
@@ -7,6 +7,10 @@
"redis": {
}
},
+ "cloudfiles":{
+ "username": "...",
+ "apiKey": "..."
+ },
"auth": {
"twitter": {
"everyauth": {
View
@@ -17,7 +17,8 @@ var util = require('util'),
stylus = require('stylus'),
mongoose = require('mongoose'),
mongooseAuth = require('mongoose-auth'),
- redis = require('redis');
+ redis = require('redis'),
+ cdn = require('connect-cdn');
var RedisStore = require('connect-redis')(express),
EventEmitter = process.EventEmitter,
@@ -30,6 +31,8 @@ var RedisStore = require('connect-redis')(express),
var Server = server.Server = function Server(options) {
EventEmitter.call(this);
+ var that = this;
+
this.options = options = utils.merge({
port: 8081,
host: '0.0.0.0',
@@ -45,6 +48,8 @@ var Server = server.Server = function Server(options) {
this.initDb();
+ var cdnMiddleware;
+
this.app = express.createServer(
express.cookieParser(),
express.session({
@@ -54,10 +59,30 @@ var Server = server.Server = function Server(options) {
maxAge: 1e3 * 3600 * 24 * 2
}
}),
+ cdnMiddleware = cdn({
+ debug: true,
+ root: __dirname + '/../../public',
+ cloudfiles: {
+ auth: options.cloudfiles
+ }
+ }, function() {
+ that.listen();
+ }),
stylus.middleware({
src: __dirname + '/../../public',
dest: __dirname + '/../../public',
- compress: true
+ compile: function(str, path) {
+ return stylus(str)
+ .set('filename', path)
+ .set('compress', true)
+ // Export `cdn` method to stylus
+ .define('cdn', function(url) {
+ url = url.toString().replace(/^"(.*)"$/, '$1');
+ url = cdnMiddleware.cdn(url, true);
+
+ return new (stylus.nodes.String)(url);
+ });
+ }
}),
express.static(__dirname + '/../../public'),
express.bodyParser(),
@@ -72,11 +97,10 @@ var Server = server.Server = function Server(options) {
// Add dynamic view handlers
mongooseAuth.helpExpress(this.app);
+ cdn.expressHelper(this.app);
// Apply routes
this.routes();
-
- this.listen();
};
util.inherits(Server, EventEmitter);
View
@@ -16,7 +16,8 @@
"mongoose-auth": ">= 0.0.11",
"connect-redis": ">= 1.0.6",
"redis": ">= 0.6.0",
- "stylus": ">= 0.3.14"
+ "stylus": ">= 0.3.14",
+ "connect-cdn": ">= 0.1.0"
},
"scripts": {
View
@@ -11,7 +11,7 @@ box-shadow()
text-shadow()
text-shadow arguments
-webkit-text-shadow arguments
- -moz-text-shadow
+ -moz-text-shadow arguments
border-radius()
border-radius arguments
-webkit-border-radius arguments
@@ -25,8 +25,8 @@ transform()
@font-face
font-family 'CopseRegular'
- src url('/fonts/Copse-Regular-webfont.eot')
- src url('/fonts/Copse-Regular-webfont.eot?#iefix') format('embedded-opentype'), url('/fonts/Copse-Regular-webfont.woff') format('woff'), url('/fonts/Copse-Regular-webfont.ttf') format('truetype'), url('/fonts/Copse-Regular-webfont.svg#CopseRegular') format('svg')
+ src url(cdn('/fonts/Copse-Regular-webfont.eot'))
+ src url(cdn('/fonts/Copse-Regular-webfont.eot?#iefix')) format('embedded-opentype'), url(cdn('/fonts/Copse-Regular-webfont.woff')) format('woff'), url(cdn('/fonts/Copse-Regular-webfont.ttf')) format('truetype'), url(cdn('/fonts/Copse-Regular-webfont.svg#CopseRegular')) format('svg')
font-weight normal
font-style normal
View
@@ -5,9 +5,9 @@ html
meta(http-equiv="X-UA-Compatible", content="IE=Edge;chrome=1")
link(href="http://fonts.googleapis.com/css?family=Droid+Sans|Droid+Sans+Mono", rel="stylesheet")
- link(href="/css/style.css", rel="stylesheet")
+ link(href=cdn("/css/style.css"), rel="stylesheet")
- script(src="/js/jquery-1.6.1.min.js")
+ script(src=cdn("/js/jquery-1.6.1.min.js"))
- if (typeof title !== 'undefined')
title Slides.IO - #{title}

0 comments on commit 5fa081e

Please sign in to comment.