You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
3.2 KiB
124 lines
3.2 KiB
var BOB_mod_path = require('path');
|
|
var BOB_mod_mkdirp = require('mkdirp');
|
|
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 BOB_cfg_config = BOB_initConfig();
|
|
|
|
var routes = require('./routes/index')(BOB_cfg_config);
|
|
var users = require('./routes/users');
|
|
|
|
var app = express();
|
|
|
|
// view engine setup
|
|
app.set('views', path.join(__dirname, 'views'));
|
|
app.set('view engine', 'ejs');
|
|
|
|
// uncomment after placing your favicon in /public
|
|
//app.use(favicon(__dirname + '/public/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, 'public')));
|
|
|
|
app.use('/', routes);
|
|
app.use('/users', users);
|
|
|
|
// 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: {}
|
|
});
|
|
});
|
|
|
|
app.setSocketIo = function(pSocketIo) {
|
|
BOB_cfg_config.io = pSocketIo;
|
|
|
|
pSocketIo.on('connection', function(socket){
|
|
console.log('New client connected', socket.id);
|
|
|
|
socket.on('event', function(data){
|
|
console.log("event");
|
|
});
|
|
socket.on('disconnect', function(){
|
|
console.log("disconnect");
|
|
});
|
|
});
|
|
}
|
|
|
|
module.exports = app;
|
|
|
|
|
|
|
|
function BOB_initConfig() {
|
|
// Config
|
|
var cfgConfig = {
|
|
background : '#ffffff',
|
|
margins : 0.005,
|
|
style : 'default',
|
|
nbPicture : 4,
|
|
cropSize : {
|
|
width : 900,
|
|
height : 1200
|
|
},
|
|
pictNames : [],
|
|
layout : [],
|
|
booths : {},
|
|
paths : {
|
|
final : "",
|
|
template : "",
|
|
prebuilt : "",
|
|
original : ""
|
|
},
|
|
footer : BOB_mod_path.resolve(__dirname, './public/img/footer', 'm-cloclo.jpg')
|
|
};
|
|
// Init PATH
|
|
cfgConfig.paths.final = BOB_mod_path.resolve(__dirname, './public/img/final');
|
|
cfgConfig.paths.final_ld = BOB_mod_path.resolve(__dirname, './public/img/final_ld');
|
|
cfgConfig.paths.prebuilt = BOB_mod_path.resolve(__dirname, './public/img/prebuilt');
|
|
cfgConfig.paths.template = BOB_mod_path.resolve(__dirname, './public/img/template');
|
|
cfgConfig.paths.original = BOB_mod_path.resolve(__dirname, './public/img/original');
|
|
|
|
BOB_mod_mkdirp.sync(cfgConfig.paths.final);
|
|
BOB_mod_mkdirp.sync(cfgConfig.paths.final_ld);
|
|
BOB_mod_mkdirp.sync(cfgConfig.paths.prebuilt);
|
|
BOB_mod_mkdirp.sync(cfgConfig.paths.original);
|
|
|
|
// Init pinctures names
|
|
for( var index = 0; index < cfgConfig.nbPicture; index ++ ) {
|
|
(function(pId) {
|
|
cfgConfig.pictNames.push('pict_'+pId+'.jpg');
|
|
})(index);
|
|
}
|
|
|
|
return cfgConfig;
|
|
}
|