Skip to content

Instantly share code, notes, and snippets.

@gpolaert
Last active June 23, 2016 17:52
Show Gist options
  • Select an option

  • Save gpolaert/5066e7144605e4b91b5fb04f76462dfb to your computer and use it in GitHub Desktop.

Select an option

Save gpolaert/5066e7144605e4b91b5fb04f76462dfb to your computer and use it in GitHub Desktop.
nodejs-talk
var template_engine = 'dust',
domain = 'localhost';
var express = require('express'),
routes = require('./routes'),
http = require('http'),
store = new express.session.MemoryStore,
path = require('path'),
flash = require('connect-flash'),
fs = require('fs');
var app = express();
// LOG
var winston = require('winston');
var expressWinston = require('express-winston');
require('winston-logstash');
app.use(expressWinston.logger({
transports: [
new (winston.transports.Logstash)({
port: 10514,
host: 'api.logmatic.io',
meta: { logmaticKey:'i2t7g8GRRImzb8rjDqDRUg' },
node_name: 'my node name',
json: true
})
]
}));
// Configuration
try {
var configJSON = fs.readFileSync(__dirname + "/config.json");
var config = JSON.parse(configJSON.toString());
} catch(e) {
console.error("File config.json not found or is invalid: " + e.message);
process.exit(1);
}
routes.init(config);
if ( template_engine == 'dust' ) {
var dust = require('dustjs-linkedin'),
cons = require('consolidate');
app.engine('dust', cons.dust);
}
app.configure(function() {
app.set('template_engine', template_engine);
app.set('domain', domain);
app.set('port', config.port || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', template_engine);
app.use(express.favicon());
app.use(express.compress());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({ secret: 'whatever', store: store }));
app.use(express.session());
app.use(express.static(path.join(__dirname, 'public')));
app.use(flash());
app.use(app.router);
});
app.configure('development', function(){
app.use(express.errorHandler());
app.locals.inspect = require('util').inspect;
});
app.get('/', routes.index);
app.get('/signup', routes.signup);
app.post('/signup', routes.completesignup);
app.get('/signin', routes.signin);
app.post('/login', routes.dologin);
app.get('/signout', routes.signout);
<!DOCTYPE html>
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta content="IE=Edge,chrome=1" http-equiv="X-UA-Compatible">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<title>PizzaShop</title>
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.1/html5shiv.js" type="text/javascript"></script>
<![endif]-->
<script src="../js/application.js" type="text/javascript"></script>
<link href="../css/application.css" media="all" rel="stylesheet" type="text/css">
<link href="../images/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon">
<script type="text/javascript" src="../js/logmatic.min.js"></script>
<script>
logmatic.init('i2t7g8GRRImzb8rjDqDRUg');
logmatic.setBulkOptions({ lingerMs: 1, maxPostCount: 10, maxWaitingCount: -1 });
logmatic.setMetas({'userId': '1234'});
logmatic.setSendErrors('error');
logmatic.setSendConsoleLogs('severity');
logmatic.setIPTracking('client.IP');
logmatic.setUserAgentTracking('client.user-agent');
logmatic.setURLTracking('url');
var log = function(e) {
logmatic.log('Action "'+ e.type+'" fired on ' + e.target.href, { target: e.target } );
};
</script>
</head>
<body style="zoom: 1;">
{>"inc/header"/}
<h2 style = "margin-left:55px">{title}</h2>
{+content}
This is the base content.
{/content}
{>"inc/footer"/}
</body>
</html>
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment