Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Created simple api returning blogposts.

  • Loading branch information...
rasvaan committed Aug 22, 2016
1 parent 471ddd4 commit 5e5f091c8925e509fb385e7990fd044171363eb0
Showing with 10 additions and 65 deletions.
  1. +2 −3 .gitignore
  2. +3 −22 package.json
  3. +4 −28 src/index.js
  4. +1 −12 src/routes/index.js
@@ -1,5 +1,4 @@
node_modules
npm-debug.log
posts.json
*.log
*_credentials.js
digibird.log
posts.json
@@ -4,40 +4,21 @@
"private": true,
"scripts": {
"start": "node ./src",
"startDev": "concurrently --kill-others \"npm run nodemon\" \"npm run webpackWatch\"",
"build": "webpack --progress --colors",
"nodemon": "nodemon ./src/index.js",
"webpackWatch": "webpack --progress --colors --watch",
"startDev": "nodemon ./src/index.js",
"test": "return 1"
},
"repository": {
"type": "git",
"url": "https://github.com/rasvaan/digibird"
"url": "https://github.com/rasvaan/digibird_api"
},
"dependencies": {
"body-parser": "~1.15.2",
"cookie-parser": "~1.4.3",
"express": "~4.14.0",
"express-handlebars": "^3.0.0",
"font-awesome": "^4.6.3",
"jquery": "^3.1.0",
"winston": "^2.2.0",
"wordpress": "^1.2.1"
},
"devDependencies": {
"bootstrap-loader": "^1.1.0",
"bootstrap-sass": "^3.3.7",
"concurrently": "^2.2.0",
"css-loader": "^0.23.1",
"extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^0.9.0",
"font-awesome-sass-loader": "^1.0.1",
"node-sass": "^3.8.0",
"nodemon": "^1.9.2",
"resolve-url-loader": "^1.6.0",
"sass-loader": "^4.0.0",
"style-loader": "^0.13.1",
"url-loader": "^0.5.7",
"webpack": "^1.13.1"
"nodemon": "^1.9.2"
}
}
@@ -1,7 +1,4 @@
'use strict';

var express = require('express');
var exphbs = require('express-handlebars');
var path = require('path');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
@@ -12,19 +9,14 @@ var routes = require('./routes');

var app = express();

app.engine('.hbs', exphbs({extname: '.hbs'}));
app.set('view engine', '.hbs');
routes.set(app);

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());

app.use(express.static(path.resolve(__dirname, '..', 'static')));
app.use(express.static(path.resolve(__dirname, '..', 'assets')));

// logging to file
winston.add(winston.transports.File, {filename: 'digibird.log'});
winston.add(winston.transports.File, {filename: 'digibird_api.log'});

// scheduled tasks
setInterval(function() {
@@ -40,27 +32,11 @@ app.use(function(req, res, next) {
});

// error handlers

// development error handler, will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
winston.log(err);
res.status(err.status || 500);
res.render('error', {
message: err.message
});
});
}

// 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
});
winston.log(err);
});


app.listen(3000, function() {
winston.log('info', 'Started server on 3000.');
app.listen(3030, function() {
winston.log('info', 'Started server on 3030.');
});
@@ -1,15 +1,6 @@
var blogUtils = require('../helpers/blog');

module.exports.set = function(app) {

app.get('/', function(req, res) {
res.render('home');
});

app.get('/people', function(req, res) {
res.render('people');
});

app.get('/blog', function(req, res) {
// get cached blog posts
var blogPosts = blogUtils.readCacheJson();
@@ -18,9 +9,7 @@ module.exports.set = function(app) {
for (var i=0; i<blogPosts.length; i++)
blogPosts[i].content = blogPosts[i].content.replace(/\s*\[.*?\]\s*/g, '');

var data = { posts: blogPosts };

// send the blog posts to the client 'blog' page
res.render('blog', data);
res.send(JSON.stringify({ posts: blogPosts }));
});
};

0 comments on commit 5e5f091

Please sign in to comment.
You can’t perform that action at this time.