Skip to content

Commit

Permalink
(*)init project
Browse files Browse the repository at this point in the history
  • Loading branch information
wangliang committed Oct 27, 2015
0 parents commit 5dff2a4
Show file tree
Hide file tree
Showing 74 changed files with 34,881 additions and 0 deletions.
124 changes: 124 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*jslint node:true */
/*jslint nomen:true */
'use strict';
// form npm
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 passport = require('passport');
var session = require('express-session');
var i18n = require("i18n");
var flash = require("connect-flash");

// from freesun
// process service
var ps = require('./freesun/services/processservice');
// system service
var ss = require('./freesun/services/systemservice');
// tail service
var ts = require('./freesun/services/tailfileservice');
// tail service
var us = require('./freesun/services/updateservice');
// config
var config = require('./freesun/env/config');
// routes
var home = require('./routes/index');
var login = require('./routes/login');
var proj = require('./routes/project');
var proc = require('./routes/process');
var webr = require('./routes/webserver');
var upld = require('./routes/upload');
var upgrade = require('./routes/upgrade');

var app = express();

i18n.configure({
locales: ['zh_CN', 'en'],
directory: __dirname + '/locales'
});

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.engine('html', require('jade').__express);

app.use(favicon(path.join(__dirname, 'static', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'static')));
app.use(session({
secret: 'axNurse',
resave: true,
saveUninitialized: true
}));
app.use(i18n.init);


if (config.auth.enable) {
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());

var initPassport = require('./freesun/passport/init');
initPassport(passport);
}
// start service
ps.start();
ss.start();
ts.start();
us.start();
//put it
app.set('fs.update.service', us);

setInterval(function () {
if (global.gc) {
global.gc();
}
}, 5000);

// routes
app.use('/', home);
app.use('/login', login);
app.use('/project', proj);
app.use('/process', proc);
app.use('/webserver', webr);
app.use('/upload', upld);
app.use('/upgrade', upgrade);

// catch 404 and forward to error handler
app.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 (app.get('env') === 'development') {
app.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
app.use(function (err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});

module.exports = app;
6 changes: 6 additions & 0 deletions bin/json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var Flow = require('..\\freesun\\temp\\install').Flow;
var Flows = require('..\\freesun\\temp\\update').Flow;
console.log(Flows);

var xx = new Flows();
console.log(Flows);
11 changes: 11 additions & 0 deletions bin/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Created by rain on 2015/8/27.
*/

var us = require('../freesun/services/updateservice');
var fs = require('graceful-fs');
fs.lstat('D:\\svn\\FS-axNurse-svn\\trunk\\code\\runtime\\app/Server/NGETService', function (err, stats) {
console.log(err);
});

us.run(0, 'D:\\svn\\FS-axNurse-svn\\trunk\\code\\uploads\\upload_b5bc7a664fb4818990709d8cc007dd96.zip');
92 changes: 92 additions & 0 deletions bin/www
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/usr/bin/env node

/**
* Module dependencies.
*/
/*jslint node:true */
'use strict';

var app = require('../app');
var debug = require('debug')('axnurse:server');
var http = require('http');

/**
* Get port from environment and store in Express.
*/

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**
* Create HTTP server.
*/

var server = http.createServer(app);

/**
* Listen on provided port, on all network interfaces.
*/

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
* Normalize a port into a number, string, or false.
*/

function normalizePort(val) {
var port = parseInt(val, 10);

if (isNaN(port)) {
// named pipe
return val;
}

if (port >= 0) {
// port number
return port;
}

return false;
}

/**
* Event listener for HTTP server "error" event.
*/

function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}

var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;

// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}

/**
* Event listener for HTTP server "listening" event.
*/

function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
10 changes: 10 additions & 0 deletions build-package.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
style-loader
css-loader
jsx-loader
react
react-router
react-dropzone
superagent
sweetalert
q
ws
26 changes: 26 additions & 0 deletions freesun/env/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Created by rain on 2015/8/5.
*/
/*jslint node:true */
'use strict';

var config = {
auth: {
enable: true
},
ws: {
process: 8100,
processInterval: 1000,
system: 8300,
systemInterval: 1000,
tail: 8200,
update: 8400,
backupClearInterval: 1000 * 60 * 60 * 24
},
debug: true,
project: {
watch: false
}
};

module.exports = config;
22 changes: 22 additions & 0 deletions freesun/env/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Created by rain on 2015/8/15.
*/
/*jslint node:true */
/*jslint nomen:true */
'use strict';
var winston = require('winston');
var path = require('path');

var logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)({
colorize: 'all'
}),
new (winston.transports.File)({
filename: path.join(__dirname, '../axNurse.log')
})
],
exitOnError: false
});

module.exports = logger;
Loading

0 comments on commit 5dff2a4

Please sign in to comment.