Skip to content

Instantly share code, notes, and snippets.

@daimajia
Last active December 18, 2015 00:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daimajia/5695899 to your computer and use it in GitHub Desktop.
Save daimajia/5695899 to your computer and use it in GitHub Desktop.
nodejs / appjs / express / jade example
/*
author: daimajia
name: appjs Express example
email: daimajia@gmail.com
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