Last active
December 18, 2015 00:19
-
-
Save daimajia/5695899 to your computer and use it in GitHub Desktop.
nodejs / appjs / express / jade example
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
/* | |
author: daimajia | |
name: appjs Express example | |
email: [email protected] | |
any question feel free to email me :) | |
*/ | |
var appjs = module.exports = require('appjs'); | |
var express = require('express'); | |
var utils = require('util');// Create express server for routing | |
appjs.serveFilesFrom(__dirname + '/content'); | |
var appRouter = express(); | |
/* | |
*This is default views jade files directory. | |
*Remeber to create a index.jade file in this directory. | |
*/ | |
appRouter.set('views',__dirname + '/content'); | |
appRouter.use(express.bodyParser()); | |
appRouter.engine('jade', require('jade').__express); | |
appRouter.engine('html', require('ejs').renderFile); | |
/** | |
* Set up the express routes | |
*/ | |
appRouter.get('/', function(req, res, next){ | |
res.render('index.jade', { name: 'Hello Jade!' }); | |
}); | |
appRouter.use(express.static(__dirname + '/content')); | |
/** | |
* Setup AppJS | |
*/ | |
// override AppJS's built in request handler with connect | |
appjs.router.handle = appRouter.handle.bind(appRouter); | |
// have express listen on a port:51686 | |
appRouter.listen(23453); | |
var window = appjs.createWindow('http://localhost:23453/', { | |
width : 640, | |
height: 460, | |
icons : __dirname + '/content/icons' | |
}); | |
window.on('create', function(){ | |
console.log("Window Created"); | |
window.frame.show(); | |
window.frame.center(); | |
}); | |
window.on('ready', function(){ | |
window.require = require; | |
window.process = process; | |
window.module = module; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment