标签:
var express = require(‘express‘);
var path = require(‘path‘);
var favicon = require(‘serve-favicon‘);
var logger = require(‘morgan‘);
var cookieParser = require(‘cookie-parser‘);
var bodyParser = require(‘body-parser‘);
var routes = require(‘./routes/index‘);
var users = require(‘./routes/users‘);
var appRouter = express();
// view engine setup
appRouter.set(‘views‘, path.join(__dirname, ‘views‘));
appRouter.set(‘view engine‘, ‘jade‘);
// uncomment after placing your favicon in /public
//appRouter.use(favicon(path.join(__dirname, ‘public‘, ‘favicon.ico‘)));
appRouter.use(logger(‘dev‘));
appRouter.use(bodyParser.json());
appRouter.use(bodyParser.urlencoded({ extended: false }));
appRouter.use(cookieParser());
appRouter.use(express.static(path.join(__dirname, ‘public‘)));
appRouter.use(‘/‘, routes);
appRouter.use(‘/users‘, users);
// catch 404 and forward to error handler
appRouter.use(function(req, res, next) {
var err = new Error(‘Not Found‘);
err.status = 404;
next(err);
});
// error handlers
// development error handler
// will print stacktrace
if (appRouter.get(‘env‘) === ‘development‘) {
appRouter.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render(‘error‘, {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
appRouter.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render(‘error‘, {
message: err.message,
error: {}
});
});
appRouter.listen(3000,function(){
console.log("sss");
})
var app = module.exports = require(‘appjs‘);
app.serveFilesFrom(__dirname + ‘/content‘);
var menubar = app.createMenu([{
label:‘&File‘,
submenu:[
{
label:‘E&xit‘,
action: function(){
window.close();
}
}
]
},{
label:‘&Window‘,
submenu:[
{
label:‘Fullscreen‘,
action:function(item) {
window.frame.fullscreen();
console.log(item.label+" called.");
}
},
{
label:‘Minimize‘,
action:function(){
window.frame.minimize();
}
},
{
label:‘Maximize‘,
action:function(){
window.frame.maximize();
}
},{
label:‘‘//separator
},{
label:‘Restore‘,
action:function(){
window.frame.restore();
}
}
]
}]);
menubar.on(‘select‘,function(item){
console.log("menu item "+item.label+" clicked");
});
var trayMenu = app.createMenu([{
label:‘Show‘,
action:function(){
window.frame.show();
},
},{
label:‘Minimize‘,
action:function(){
window.frame.hide();
}
},{
label:‘Exit‘,
action:function(){
window.close();
}
}]);
var statusIcon = app.createStatusIcon({
icon:‘./data/content/icons/32.png‘,
tooltip:‘AppJS Hello World‘,
menu:trayMenu
});
var window = app.createWindow(‘http://localhost:3000/‘,{
width : 640,
height : 460,
icons : __dirname + ‘/content/icons‘
});
/*
var window = appjs.createWindow(‘http://localhost:23453/‘, {
width : 640,
height: 460,
icons : __dirname + ‘/content/icons‘
});
var http = require(‘http‘);
server = http.createServer(function (req, res) {
res.writeHeader(200, {"Content-Type": "text/plain"});
res.end("Hello oschina\n");
})
server.listen(8000);
console.log("httpd start @8000");
var window = app.createWindow({
width : 1024,
height : 768,
icons : __dirname + ‘/content/icons‘,
showChrome : false,
alpha: true,
autoResize: false,
resizable: true,
margin: 0
/***************************** defaults ********************************
* url : ‘http://appjs‘, // serve static file root and routers
* autoResize : false, // resizes in response to html content
* showChrome : true, // show border and title bar
* resizable : false, // control if users can resize window
* disableSecurity: true, // allow cross origin requests
* opacity : 1, // flat percent opacity for window
* alpha : false, // per-pixel alpha blended (Win & Mac)
* fullscreen : false, // client area covers whole screen
* left : -1, // centered by default
* top : -1, // centered by default
});*************************************************************************/
window.on(‘create‘, function(){
console.log("Window Created");
window.frame.show();
window.frame.center();
window.frame.setMenuBar(menubar);
});
window.on(‘ready‘, function(){
console.log("Window Ready");
window.process = process;
window.module = module;
function F12(e){ return e.keyIdentifier === ‘F12‘ }
function Command_Option_J(e){ return e.keyCode === 74 && e.metaKey && e.altKey }
window.addEventListener(‘keydown‘, function(e){
if (F12(e) || Command_Option_J(e)) {
window.frame.openDevTools();
}
});
});
window.on(‘close‘, function(){
console.log("Window Closed");
});
标签:
原文地址:http://www.cnblogs.com/jayruan/p/5184620.html