-
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.
- Loading branch information
Showing
3 changed files
with
202 additions
and
3 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
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = { | ||
port: 3200, | ||
env: 'development' | ||
} | ||
|
||
/* | ||
module.exports = { | ||
port: 8001, | ||
env: 'production', | ||
workers: 10 | ||
} | ||
*/ |
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 |
---|---|---|
@@ -0,0 +1,179 @@ | ||
#!/usr/bin/env node | ||
|
||
//Needed for monit/upstart | ||
//Change directory into the script directory so includes resolve | ||
process.chdir(__dirname); | ||
|
||
var express = require('express'), | ||
path = require('path'), | ||
fs = require('fs'), | ||
YUI = require('yui3').YUI, | ||
DEBUG = true; | ||
|
||
|
||
//Create the express application and allow the use of Spark (http://github.com/senchalabs/spark) | ||
var app = module.exports = express.createServer(); | ||
/** | ||
* Create the external instance that will host our "express" server. | ||
* For a performance gain, you can "use" common modules here, so they | ||
* are available when a new instance is created per request. | ||
*/ | ||
YUI({ debug: false }).use('express', 'node', function(Y) { | ||
|
||
//Configure it with some simple configuration options. | ||
app.configure(function(){ | ||
app.use(express.methodOverride()); | ||
app.use(express.bodyDecoder()); | ||
app.use(express.cookieDecoder()); | ||
app.use(app.router); | ||
app.use(express.conditionalGet()); | ||
app.use(express.cache()); | ||
app.use(express.gzip()); | ||
app.use(express.staticProvider(__dirname + '/assets')); | ||
}); | ||
|
||
//Set the development environment to debug, so YUI modues echo log statements | ||
app.configure('development', function(){ | ||
DEBUG = true; | ||
}); | ||
//Set the production environment to halt all debug logs. | ||
app.configure('production', function(){ | ||
DEBUG = false; | ||
}); | ||
|
||
/** | ||
* This version of the YUIExpress engine comes with a simple YUI combo handler | ||
* So you can put "use" inside your locals var on render: | ||
* | ||
* res.render('index.html', { | ||
* locals: { | ||
* use: ['dd', 'tabview'] | ||
* } | ||
* }); | ||
* | ||
* This will load a URL into the page like this: | ||
* <script src="/combo?dd&tabview"></script> | ||
* | ||
* Note, currently it has to be "/combo", the internal renderer doesn't | ||
* know what you set this to. Eventually we can add it to YUI.configure. | ||
*/ | ||
app.get('/combo', YUI.combo); | ||
|
||
/** | ||
* This is the "black magic" part. This tells Express to use YUI to render | ||
* all HTML pages | ||
*/ | ||
app.register('.html', YUI); | ||
|
||
|
||
/** | ||
* These partials will be added to every page served by YUI, good for templating. | ||
* They can be added to by locals.partials on a per page basis. A partial looks like this: | ||
* { | ||
* name: 'header', //Name of the /views/partial/{name}.html file to load | ||
* method: 'append', //append,prepend,appendChild | ||
* node: '#conent', //Any valid selector | ||
* enum: 'one', //one,all | ||
* fn: function //The callback function to run after the action. | ||
* } | ||
* Defaults to enum: "one" and method: "append" | ||
*/ | ||
|
||
YUI.partials = [ | ||
{ | ||
name: 'layout_head', | ||
node: 'head' | ||
} | ||
]; | ||
|
||
/** | ||
* YUI.configure allows you to configure routes for the yui2 & yui3 assests. | ||
* With this config you will serve yui2 assets from /yui2/ and yui3 assets from | ||
* /yui3 | ||
* | ||
*/ | ||
YUI.configure(app, { | ||
yui2: '/yui2/', | ||
yui3: '/yui3/' | ||
}); | ||
|
||
/** | ||
* The route controller for the default page: / | ||
* This is a simple example of serving a static HTML page with a little | ||
* Javascript to enhance the page. | ||
*/ | ||
app.get('/', function(req, res) { | ||
//Render from ./views/index.html | ||
res.render('index.html', { | ||
//Locals used by the YUI renderer | ||
locals: { | ||
/** | ||
* This is the content placeholder in your ./views/layout.html file. | ||
* The content of index.html will be inserted here. | ||
*/ | ||
content: '#content', | ||
/** | ||
* Standard object hash to be passed to Y.Lang.sub after the | ||
* content has been loaded, but before it's inserted into the YUI | ||
* instance on render. | ||
*/ | ||
sub: { | ||
title: 'YUI3 Gallery: Dashboard' | ||
}, | ||
/** | ||
* The after method will be invoked after the layout.html file | ||
* has been loaded into the instance. This allows you to change | ||
* the total layout, after all the peices have been assembled. | ||
*/ | ||
after: function(Y, options, partial) { | ||
Y.one('title').set('innerHTML', 'YUI3 Gallery: Dashboard'); | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
app.get('/api/:id?', function(req, res) { | ||
require('./pages/module.js').partial(req, res, { | ||
debug: DEBUG, | ||
module: req.params.id, | ||
partial: 'module_api.html' | ||
}); | ||
}); | ||
|
||
app.get('/yeti/:id?', function(req, res) { | ||
require('./pages/module.js').partial(req, res, { | ||
debug: DEBUG, | ||
module: req.params.id, | ||
partial: 'module_yeti.html' | ||
}); | ||
}); | ||
|
||
app.get('/jslint/:id?', function(req, res) { | ||
require('./pages/module.js').partial(req, res, { | ||
debug: DEBUG, | ||
module: req.params.id, | ||
partial: 'module_jslint.html' | ||
}); | ||
}); | ||
|
||
app.get('/module/:id?', function(req, res) { | ||
require('./pages/module.js').render(req, res, { | ||
debug: DEBUG, | ||
module: req.params.id, | ||
page: 'module.html' | ||
}); | ||
}); | ||
|
||
app.get('/modules', function(req, res) { | ||
require('./pages/modules.js').render(req, res, { | ||
debug: DEBUG, | ||
bucket: 'oncdn' | ||
}); | ||
}); | ||
|
||
app.listen(8001); | ||
if (DEBUG) { | ||
console.log('Server running at: http://localhost:8001/'); | ||
} | ||
|
||
}); |