From 24ef41ca34cc302066869cec256dd90dd7792bca Mon Sep 17 00:00:00 2001 From: jkaplon Date: Tue, 16 Feb 2016 17:52:38 -0500 Subject: [PATCH] Initial commit, all currently broken. --- .gitignore | 5 +++++ server.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ views/index.hbs | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 .gitignore create mode 100644 server.js create mode 100644 views/index.hbs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a5507d9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/keymap/* +/lib/* +/mode/* +/note-data/* +index.html diff --git a/server.js b/server.js new file mode 100644 index 0000000..6fc0bac --- /dev/null +++ b/server.js @@ -0,0 +1,46 @@ +var express = require("express"); +var hbs = require('express-hbs'); +require('handlebars-form-helpers').register(hbs.handlebars); +var bodyParser = require("body-parser"); +var app = express(); +var winston = require('winston'); +winston.add(winston.transports.File, { filename: './logs/notes.kaplon.us.log', maxsize: 5000000 }); // 5MB +var fileSystem = require('fs'); + +app.use(bodyParser.json()); +app.use(bodyParser.urlencoded({ extended: false })); // Not sure if both needed here. + +// Use `.hbs` for extensions and find partials in `views/partials`. +app.engine('hbs', hbs.express4({ + partialsDir: __dirname + '/views/partials' +})); +app.set('view engine', 'hbs'); +app.set('views', __dirname + '/views'); + +var notePath = __dirname + '/allNotes.txt'; + +app.get('/', function(req, res){ + winston.info("GET /"); + // Get curent text from allNotes.txt. + // How to pass that text into index.html editor control??? Still need Handlebars??? + // i may be grokking it...need to keep handlebars, though. + // read contents of allNotes.txt into a variable. + // pass that variable as data to handlebars template, {{notetxt}}. + res.render('index', {notetxt: noteTxt}, function(err, html) { + if(err !== null) { + winston.error(err); + } else { + res.send(html); + } + }); +}); + +app.post('/', function(req, res){ + winston.info(req.body); + // Stage and commit changes to allNotes.txt. + res.status(204).send('POST received'); +}); + +app.listen(3000, function() { + winston.info("Started on PORT 3000"); +}); diff --git a/views/index.hbs b/views/index.hbs new file mode 100644 index 0000000..c927d73 --- /dev/null +++ b/views/index.hbs @@ -0,0 +1,43 @@ + + + +Jody's CodeMirror + + + + + + + + +
+ + + +