Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
flaudre committed Dec 8, 2017
0 parents commit e99288a
Show file tree
Hide file tree
Showing 603 changed files with 106,630 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
config.js merge=ours
45 changes: 45 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
elneto-secret/


.sass-cache/

semantic/dist
forever.sh
public/images/galery/*
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# elneto
Source code of elneto.com
52 changes: 52 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
var devEnc = require('./elneto-secret/development');
var prodEnc = require('./elneto-secret/production');

var development = {
DEBUG_LOG : true,
DEBUG_WARN : true,
DEBUG_ERROR : true,
DEBUG_CLIENT : true,
USE_IMAGE_MAGICK : true,
redis : {
port: '6379'
},
}

var production = {
DEBUG_LOG : false,
DEBUG_WARN : false,
DEBUG_ERROR : true,
DEBUG_CLIENT : false,
APP_PORT : 20082,
redis : {
port: '6379'
},
}

var config = {
ROOT: __dirname,
DB_HOST: 'localhost',
};

module.exports = function (env) {
switch(env){
case "development": {
Object.assign(config, development);
if (devEnc) {
Object.assign(config, devEnc);
}
break;
}
case "production": {
Object.assign(config, production);
if (prodEnc) {
Object.assign(config, prodEnc);
}
break;
}
default:
console.error("Environment not found.");
}

return config;
};
71 changes: 71 additions & 0 deletions gulpfile.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
gulp = require 'gulp'
gutil = require 'gulp-util'
gulpif = require 'gulp-if'
watch = require 'gulp-watch'
less = require 'gulp-less'
coffee = require 'gulp-coffee'
clean = require 'gulp-clean'
nodemon = require 'gulp-nodemon'
buildSemantic = require('./semantic/tasks/build')

# Compile Less
gulp.task 'build-less', ->
gulp.src 'public/css/*.less'
.pipe less()
.pipe gulp.dest('public/css')
.on 'end', ->
gutil.log "Compiled less files"

# Watch Less
gulp.task 'watch-less', ->
gulp.src 'public/css/*.less'
.pipe watch('public/css/*.less')
.pipe less()
.pipe gulp.dest('public/css')
.on 'end', ->
gutil.log "Compiled less files"

gulp.task 'watch-source', ['watch-less']
gulp.task 'watch-all', ['watch-source', 'watch-semantic']

gulp.task 'build-semantic', buildSemantic
gulp.task 'build-source', ['build-less', 'build-coffee']
gulp.task 'build-all', ['build-source', 'build-semantic']
gulp.task 'build', ['build-source']

gulp.task 'start-server', ->
gulp.start ['watch-source']

if not nodemon_instance?
nodemon_instance = nodemon
script: 'index.js'
watch: ['.app/']
ext: 'js'
verbose: true
nodemon_instance.on 'restart', ->
gutil.log 'Restarting server'
else
nodemon_instance.emit 'restart'

gulp.task 'server', ['serve']
gulp.task 'serve', ['build-source'], ->
gulp.start ['start-server']


gulp.task 'deploy-daily', ->
gutil.log 'Stopping service ...'
try
pm2Stop = spawn.sync 'pm2', ['stop', 'graspdaily']
catch e
# ignore it
gutil.log(e)

gutil.log 'Deleting service ...'
try
pm2Delete = spawn.sync 'pm2', ['delete', 'graspdaily']
catch e
# ignore it
gutil.log(e)

gutil.log 'Starting service ...'
startService = spawn.sync 'pm2', ['start', 'server.js', '--name', '"graspdaily"', '--', 'NODE_ENV=local']
4 changes: 4 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Note the new way of requesting CoffeeScript since 1.7.x
require('coffee-script/register');
// This bootstraps your Gulp's main file
require('./gulpfile.coffee');
110 changes: 110 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
var express = require('express');
var app = express();

var path = require('path'); // path module
var favicon = require('serve-favicon'); // favicon module
var logger = require('morgan'); // Logging engine
var cookieParser = require('cookie-parser'); // Cookie parser
var fs = require('fs'); // Filesystem module
var crypto = require('crypto'); // Cryptography module

// Body parser
var bodyParser = require('body-parser'); // Request body parser

app.use(bodyParser.urlencoded({ extended: true })) // parse application/x-www-form-urlencoded
app.use(bodyParser.json()) // parse application/json


var env = process.env.NODE_ENV || 'development';

// Load config
var config = require('./config')(env);
console.log(config);

app.use(function(req, res, next){
req.config = config;
next();
});

var port = process.env.PORT || config.APP_PORT || 3000;
var host = process.env.HOST || config.APP_HOST || "localhost";

app.set('port', port);
app.set('host', host);

// Database
var db = require('./mongodb/connect');
db.connect(config, env);

// Load templating engine
var exphbs = require('express-handlebars');
var helpers = require('./lib/helpers');

// Server
var debug = require('debug')('elneto');
var http = require('http'); // http server
var app_name = "Elneto Fotos";

// Initialize redis based session
var session = require('express-session');
var RedisStore = require('connect-redis')(session);
var sess = {
resave: true,
saveUninitialized: true,
secret: config.redis.SECRET,
cookie:{ maxAge:24*60*60*1000 },
store: new RedisStore({
host: 'localhost',
port: config.redis.port
})
}
app.use(session(sess));

// Load connect-flash
var flash = require('connect-flash');
app.use(flash());

// Passport.js for authentication
var passport = require('passport');
app.use(passport.initialize());
app.use(passport.session());



// Create `ExpressHandlebars` instance with a default layout.
var hbs = exphbs.create({
defaultLayout: 'main',
helpers : helpers,

// Uses multiple partials dirs, templates in "shared/templates/" are shared
// with the client-side of the app (see below).
partialsDir: [
'shared/templates/',
'views/partials/',
'views/scripts/'
]
});

// Register `hbs` as our view engine using its bound `engine()` function.
app.engine('handlebars', hbs.engine);
app.set('view engine', 'handlebars');

// Load router
app.use(function(req, res, next) {
if (req.path.substr(-1) == '/' && req.path.length > 1) {
var query = req.url.slice(req.path.length);
res.redirect(301, req.path.slice(0, -1) + query);
} else {
next();
}
});
app.use('/', require('./routes/router.js'));

debug('Booting %s', app_name);

//var server = http.createServer(app);
var server = app.listen(app.get('port'), function(){
console.log('Express server listening on ' + app.get('host') + ":" + app.get('port'));
});

module.exports = app;
63 changes: 63 additions & 0 deletions lib/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
'use strict';

var monthNames = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"]

var dayNames = ["Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado", "Domingo"]

var shortDayNames = [];
dayNames.forEach(function(dayName){
shortDayNames.push(dayName.slice(0,3));
});

var shortMonthNames = [];
monthNames.forEach(function(monthName){
shortMonthNames.push(monthName.slice(0,3));
});

// Helpers
exports.formatPrice = function(price){
return "CHF " + (parseFloat(price) / 100).toFixed(2);
}

exports.formatDate = function(date){
if(!date){
return "";
}

return date.getDate() + "." + date.getMonth() + "." + date.getFullYear();
}

exports.formatFullDateString = function(date){
if(!date){ return ""; }

return dayNames[date.getDay()] + ", " + date.getDate() + ". " + monthNames[date.getMonth()] + " " + date.getFullYear();
}

exports.formatDateString = function(date){
if(!date){ return ""; }

return shortDayNames[date.getDay()] + " " + date.getDate() + " " + shortMonthNames[date.getMonth()] + " " + date.getFullYear();
}

exports.isMultiDay = function(trip){
if(!trip.date_begin || !trip.date_end){ return ""; }

return (trip.date_begin.toDateString() != trip.date_end.toDateString())
}

exports.days_duration_string = function(trip){
if(!trip.date_begin || !trip.date_end){ return ""; }

var days = Math.ceil(Math.abs(trip.date_end.getTime() - trip.date_begin.getTime()) / (1000 * 3600 * 24));
return days > 1 ? days + " Tage" : days + " Tag";
}
exports.days_duration = function(trip){
if(!trip.date_begin || !trip.date_end){ return ""; }

var days = Math.ceil(Math.abs(trip.date_end.getTime() - trip.date_begin.getTime()) / (1000 * 3600 * 24));
return days;
}

exports.yell = function (msg) {
return msg.toUpperCase();
};
Binary file added mongodb/.db.js.un~
Binary file not shown.
36 changes: 36 additions & 0 deletions mongodb/connect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
var mongoose = require('mongoose');

exports.connect = function(config, env){

if(config.db.user && config.db.pass){
mongoose.connect('mongodb://' + config.db.host + ":" + config.db.port + "/" + config.db.name,
{
user: config.db.user,
pass: config.db.pass,
});
}
else
{
mongoose.connect('mongodb://' + config.db.host + ":" + config.db.port + "/" + config.db.name);
}

// CONNECTION EVENTS
// When successfully connected
mongoose.connection.on('connected', function () {
console.log('Mongoose default connection open on port ' + config.db.port);
});

// If the connection throws an error
mongoose.connection.on('error',function (err) {
console.log('Mongoose default connection error: ' + err);
});

// When the connection is disconnected
mongoose.connection.on('disconnected', function () {
console.log('Mongoose default connection disconnected');
});

mongoose.Promise = global.Promise

exports.mongoose = mongoose;
}
Loading

0 comments on commit e99288a

Please sign in to comment.