Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Got express setup in the server

  • Loading branch information...
commit b5014376bdfd47cc5170301202ad79e2bc3aa322 1 parent 33e5c27
JT Turner authored
80 lib/db.js
View
@@ -0,0 +1,80 @@
+var sqlite3 = require('sqlite3').verbose();
+var mode = sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE;
+var http = require('http');
+
+function runTest(req, res) {
+ res.writeHead(200, {'Content-Type': 'text/plain'});
+
+ var db = new sqlite3.Database(__dirname + '/blog.db', mode, function(dberror) {
+ if (dberror != null) {
+ console.log(dberror);
+ } else {
+ checkTableExists(db, 'lorem1', function (err, exists) {
+ if (err != null) {
+ console.log(err);
+ } else {
+ if (!exists) {
+ createDbTable(db, function() {
+ res.write('Created Database table lorem1...');
+ insertTestDate(db, function() {
+ getRecords(db, function() {
+ res.end('Hello World\nGot records for tinyblog...');
+ });
+ });
+ });
+ } else {
+ getRecords(db, function() {
+ res.end('Hello World\nGot records for tinyblog...');
+ });
+ }
+ }
+ });
+
+ }
+ });
+}
+
+function insertTestDate(db, callback) {
+ db.serialize(function() {
+ var stmt = db.prepare("INSERT INTO lorem1 VALUES (?)");
+ for (var i = 0; i < 10; i++) {
+ stmt.run("Ipsum " + i);
+ }
+ stmt.finalize();
+ });
+ callback();
+}
+
+function createDbTable(db, callback) {
+ db.run("CREATE TABLE lorem1 (info TEXT)", function () {
+ callback();
+ });
+}
+
+function getRecords(db, callback) {
+ db.each("SELECT rowid, info FROM lorem1", function(queryerror, row) {
+ if (queryerror != null) {
+ console.log(queryerror);
+ } else {
+ console.log(row.rowid + ": " + row.info);
+ }
+ }, function() {
+ callback();
+ });
+}
+
+//Call back returns a err and then true or false
+function checkTableExists(db, tablename, callback) {
+ try {
+ var sql = "SELECT name FROM sqlite_master WHERE type='table' AND name=?";
+ db.all(sql, tablename, function(queryerror, rows) {
+ if (rows.length <= 0) {
+ callback(null, false);
+ } else {
+ callback(null, true);
+ }
+ });
+ } catch (err) {
+ callback(err, false);
+ }
+}
16 public/stylesheets/style.css
View
@@ -0,0 +1,16 @@
+body {
+ font-family: Helvetico, Arial, Sans-Serif;
+ font-size: 16px;
+ color: #333;
+}
+
+#main {
+ width: 960px;
+ margin: 0 auto;
+ border: 1px solid #ddd;
+ padding: 1em;
+}
+
+#center {
+ text-align: center;
+}
97 server.js
View
@@ -1,80 +1,29 @@
-var sqlite3 = require('sqlite3').verbose();
-var mode = sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE;
-var http = require('http');
+var express = require('express');
-http.createServer(function (req, res) {
- res.writeHead(200, {'Content-Type': 'text/plain'});
+var app = require('express').createServer();
- var db = new sqlite3.Database(__dirname + '/blog.db', mode, function(dberror) {
- if (dberror != null) {
- console.log(dberror);
- } else {
- checkTableExists(db, 'lorem1', function (err, exists) {
- if (err != null) {
- console.log(err);
- } else {
- if (!exists) {
- createDbTable(db, function() {
- res.write('Created Database table lorem1...');
- insertTestDate(db, function() {
- getRecords(db, function() {
- res.end('Hello World\nGot records for tinyblog...');
- });
- });
- });
- } else {
- getRecords(db, function() {
- res.end('Hello World\nGot records for tinyblog...');
- });
- }
- }
- });
-
- }
- });
-}).listen(12018);
+app.set('views', __dirname + '/views');
+app.set('view engine', 'jade');
-function insertTestDate(db, callback) {
- db.serialize(function() {
- var stmt = db.prepare("INSERT INTO lorem1 VALUES (?)");
- for (var i = 0; i < 10; i++) {
- stmt.run("Ipsum " + i);
- }
- stmt.finalize();
- });
- callback();
-}
+app.configure(function(){
+ app.use(express.logger());
+ app.use(express.static(__dirname + '/public'));
+ app.use(express.errorHandler({ dumbExceptions: true, showStack: true }));
+ app.use(express.bodyParser());
+ app.use(express.cookieParser());
+ app.use(express.session({ secret: 'wHeucjf6Yk8SzNYFNMWLfDkBiKYRVWjpWSjVBj' }));
+});
-function createDbTable(db, callback) {
- db.run("CREATE TABLE lorem1 (info TEXT)", function () {
- callback();
- });
-}
+app.get('/', function(req, res){
+ res.render('index');
+});
-function getRecords(db, callback) {
- db.each("SELECT rowid, info FROM lorem1", function(queryerror, row) {
- if (queryerror != null) {
- console.log(queryerror);
- } else {
- console.log(row.rowid + ": " + row.info);
- }
- }, function() {
- callback();
- });
-}
+app.get('/tb-admin/', function(req, res){
+ res.render('index');
+});
-//Call back returns a err and then true or false
-function checkTableExists(db, tablename, callback) {
- try {
- var sql = "SELECT name FROM sqlite_master WHERE type='table' AND name=?";
- db.all(sql, tablename, function(queryerror, rows) {
- if (rows.length <= 0) {
- callback(null, false);
- } else {
- callback(null, true);
- }
- });
- } catch (err) {
- callback(err, false);
- }
-}
+app.error(function(ex, req, res, next){
+ displayErrorPage(ex, res);
+});
+
+app.listen(12018);
9 views/404.jade
View
@@ -0,0 +1,9 @@
+h1 Google+ to RSS Feed Error
+p We got the following error:
+ = errorMsg
+p Please make sure you grabed the whole user id. See
+ a(href='/') Google+ To Rss Home Page
+ .
+p This still is a beta site so it might go down from time to time. If you have any issues please submit a issue to
+ a(href='https://github.com/jtwebman/GooglePlusToRSSFeed/issues') Github Issues
+ .
2  views/index.jade
View
@@ -0,0 +1,2 @@
+h1 Title
+p This is the home page for the blog
10 views/layout.jade
View
@@ -0,0 +1,10 @@
+!!! 5
+html
+ head
+ link(rel='stylesheet', href='/stylesheets/style.css')
+ title TinyBlog
+ body
+ #main
+ #body!= body
+ #foot
+ p Footer
Please sign in to comment.
Something went wrong with that request. Please try again.