Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
166 commits
Select commit Hold shift + click to select a range
dd3133a
Add HTML
Oct 6, 2015
6580c2f
Merge pull request #4 from pstrum/basic-html
pstrum Oct 6, 2015
ac7d65d
Add initial layout architecture for Sass
Oct 6, 2015
c303f46
Merge pull request #7 from pstrum/sass-setup
pstrum Oct 6, 2015
95cdbf1
Add in icons and icons font, add imports to INDEX files
jimmynono-dd Oct 6, 2015
4056337
add in basic button styling by creating a buttons partial and using a…
jimmynono-dd Oct 6, 2015
ab91824
adjust borders on buttons
jimmynono-dd Oct 6, 2015
03efe29
Merge pull request #9 from pstrum/basicHTML
pstrum Oct 6, 2015
ef1d23b
Add css/main.css to gitignore
Oct 6, 2015
46fa0ec
Add first draft of style-guide
Oct 6, 2015
ec17c2f
Resolve merge conflicts on rebase
Oct 6, 2015
92828af
Resolve merge conflicts
Oct 6, 2015
8a1570d
Update the style guide
Oct 6, 2015
695df69
Merge pull request #10 from pstrum/style-guide
pstrum Oct 6, 2015
05ec40b
merge conflict
jimmynono-dd Oct 6, 2015
565d3f8
Merge conflicts
jimmynono-dd Oct 6, 2015
4bf3084
Add initial styles to navigation component
Oct 6, 2015
88ff6e1
Add top navigation layout
Oct 6, 2015
436cb13
Add layout for the header and page title sections
Oct 6, 2015
1edfac1
Remove superfluous navigation style sheet
Oct 6, 2015
47cf28e
Merge pull request #11 from pstrum/header-pagetitle
jimmynono-dd Oct 6, 2015
ec4b86e
styling on blog section, styling on articles
jimmynono-dd Oct 6, 2015
c78e01f
fix merge issue
jimmynono-dd Oct 6, 2015
e272e9d
Work on footer social icons
Oct 6, 2015
f0850af
Merge branch 'master' of https://github.com/pstrum/mean-stack-1 into …
Oct 6, 2015
27d3cd2
Merge pull request #12 from pstrum/basicHTML
pstrum Oct 6, 2015
02afbc0
Finish creating footer social media icons
Oct 6, 2015
087f923
begin styling of footer section
jimmynono-dd Oct 6, 2015
1cb4f21
Fix merge conflict
Oct 6, 2015
e02d675
Merge branch 'master' of https://github.com/pstrum/mean-stack-1 into …
jimmynono-dd Oct 6, 2015
00a37ba
Removed main.css from gitignore
Oct 6, 2015
3ed11b0
Merge pull request #14 from pstrum/footer-socialmedia-icons
jimmynono-dd Oct 6, 2015
ba9aa5b
fix merge conflicts
jimmynono-dd Oct 6, 2015
37d6149
style footer and resolve merge conflicts
jimmynono-dd Oct 7, 2015
629ae67
fixed an error I made, changing a font size. back to normal
jimmynono-dd Oct 7, 2015
9c61bbd
Merge pull request #15 from pstrum/sassJames
pstrum Oct 7, 2015
f07d3ec
Resolve merge conflicts
Oct 7, 2015
f28d256
Resolve merge conflicts
Oct 7, 2015
dc274de
Updates to blog post styles
Oct 6, 2015
7027a98
Remove index.js file
Oct 7, 2015
c93ce87
Styled indenting on top of page. Created classes to re-use indenting …
Oct 7, 2015
6184b4e
Merge pull request #17 from pstrum/footer-socialmedia-icons
pstrum Oct 7, 2015
67ce1f5
remove server.js from commit
jimmynono-dd Oct 7, 2015
6dad7f4
Merge branch 'master' of https://github.com/pstrum/mean-stack-1 into …
jimmynono-dd Oct 7, 2015
b79f2aa
Merge branch 'master' into feature
Oct 7, 2015
c231e66
Merge pull request #16 from pstrum/feature
jimmynono-dd Oct 7, 2015
0f92a73
Add public directory to file
jimmynono-dd Oct 7, 2015
75498e6
Merge branch 'master' of https://github.com/pstrum/mean-stack-1 into …
jimmynono-dd Oct 7, 2015
3ba9ef4
added margin to footer
jimmynono-dd Oct 7, 2015
e806997
fix changes made to experiment with server
jimmynono-dd Oct 7, 2015
b41b0fb
move fonts to work on public site
jimmynono-dd Oct 7, 2015
b5905f4
Merge pull request #20 from pstrum/sassJames
pstrum Oct 7, 2015
02e8cfc
Create server.js file
Oct 7, 2015
f583e09
Update gitignore with server.js
Oct 7, 2015
603ae6d
Update the server.js file
Oct 7, 2015
3dfa2f1
Merge branch 'master' into feature
Oct 7, 2015
7cf4b6d
express server created, talks to mongodb
jimmynono-dd Oct 7, 2015
daaff29
Merge pull request #21 from pstrum/angularJames
Oct 7, 2015
4df482a
add angular to index.html and package.json file
jimmynono-dd Oct 7, 2015
feed6f2
Update to server.js
Oct 8, 2015
54b0ecc
Merge branch 'master' into feature
Oct 8, 2015
3a03fb7
Moved sass directory to root level
Oct 8, 2015
8ba35d9
Update to server.js file
Oct 8, 2015
28ba9d8
Update to gitignore file
Oct 8, 2015
8689678
Update to gitignore file
Oct 8, 2015
fa4d12d
Add public/css/main.css to gitignore
Oct 8, 2015
ed9983c
Merge branch 'feature' of https://github.com/pstrum/mean-stack-1 into…
Oct 8, 2015
01155e6
Merge pull request #22 from pstrum/feature
jimmynono-dd Oct 8, 2015
af0c7b1
beginnings of angular, adding ng-app to html and create public/js folder
jimmynono-dd Oct 8, 2015
6952ef3
merge issues
jimmynono-dd Oct 8, 2015
4460620
Add ng-app to html
Oct 8, 2015
1db2b7d
add angular to make blog responsive, hard code test data in app.js fi…
jimmynono-dd Oct 8, 2015
a560331
Merge pull request #24 from pstrum/angularJames
Oct 8, 2015
9ae5546
Edit the index.html file
Oct 8, 2015
5b1976e
Merge branch 'master' into angular
Oct 8, 2015
cffdb10
Add initial angular files
Oct 8, 2015
f1cc2e5
Merge pull request #25 from pstrum/angular
pstrum Oct 8, 2015
5a2ed43
updatea package.json to work with angular
jimmynono-dd Oct 8, 2015
37e7b4c
Merge branch 'master' of https://github.com/pstrum/mean-stack-1 into …
jimmynono-dd Oct 8, 2015
594240d
rename and refactor app, still not working, but no errors
jimmynono-dd Oct 8, 2015
349f625
Merge pull request #26 from pstrum/angularJames
pstrum Oct 8, 2015
bef2bbf
Edit the blog post controller
Oct 8, 2015
54772b5
Merge branch 'master' of https://github.com/pstrum/mean-stack-1 into …
Oct 8, 2015
00391e0
rename app to intellyApp, fix partials to accept changed variable name
jimmynono-dd Oct 9, 2015
84eda36
Merge pull request #27 from pstrum/angularJames
Oct 9, 2015
715cc2c
Add a form partial template
Oct 9, 2015
b31b432
Merge branch 'master' of https://github.com/pstrum/mean-stack-1 into …
Oct 9, 2015
c890c12
Add blogs.ctrl script to the index.html
Oct 9, 2015
9a76b31
begin functionality of blog details
jimmynono-dd Oct 9, 2015
e29943e
Merge pull request #29 from pstrum/angularJames
pstrum Oct 9, 2015
5375541
Add initial form/add post html
Oct 9, 2015
558121c
Merge branch 'master' of https://github.com/pstrum/mean-stack-1 into …
Oct 9, 2015
69edad2
Add to gulp serve to gulpfile
Oct 9, 2015
b091446
Update package.json
Oct 9, 2015
b401c67
add delete button to blog preview
jimmynono-dd Oct 9, 2015
f5778a6
Update to form controller
Oct 9, 2015
f765833
Merge pull request #31 from pstrum/angularJames
pstrum Oct 9, 2015
287a9ec
Merge branch 'master' of https://github.com/pstrum/mean-stack-1 into …
Oct 9, 2015
d70927e
Update gulpfile
Oct 9, 2015
7dad202
Merge pull request #32 from pstrum/angular
jimmynono-dd Oct 9, 2015
65ecb2d
merge conflicts
jimmynono-dd Oct 9, 2015
a1cef9f
merge conflicts
jimmynono-dd Oct 9, 2015
6c95071
stashing gulpfile
Oct 9, 2015
10d0fe9
fix merge conflict
Oct 9, 2015
d9bb6c8
fix merge conflict
Oct 9, 2015
8705edc
Merge pull request #30 from pstrum/gulp-setup
pstrum Oct 9, 2015
e0d5915
Merge issues
jimmynono-dd Oct 9, 2015
db7fddf
get functionality on add post
jimmynono-dd Oct 9, 2015
99e309e
Merge pull request #33 from pstrum/angularJames
pstrum Oct 9, 2015
7fa0117
Update to form controller
Oct 9, 2015
db6a9e2
Add missing semicolon. Add output folder to gitignore. Fix mispelled …
Oct 9, 2015
dfceea2
add delete button to form
jimmynono-dd Oct 9, 2015
5ab3bbe
Work on limiting the number of characters in blog view
Oct 9, 2015
9279000
Merge pull request #34 from pstrum/angularJames
Oct 9, 2015
c253e7c
Change date to date format
Oct 9, 2015
4d97fd0
fix merge conflict
Oct 9, 2015
b112e50
Add breaks between paragraphs in blog post view
Oct 9, 2015
8e2767c
Merge branch 'master' of https://github.com/pstrum/mean-stack-1 into …
Oct 9, 2015
4fc941d
layout tweaks to buttons
jimmynono-dd Oct 9, 2015
50d2b8d
Merge pull request #36 from pstrum/angularJames
pstrum Oct 9, 2015
60b90bd
Merge branch 'master' of https://github.com/pstrum/mean-stack-1 into …
Oct 9, 2015
1e2dff6
Adjust the file structure
Oct 10, 2015
7cca696
small sass tweaks to page
jimmynono-dd Oct 10, 2015
596ab5a
Merge pull request #37 from pstrum/angular
pstrum Oct 10, 2015
6df1d26
Merge conflicts
jimmynono-dd Oct 10, 2015
40c3dea
Update with webpack
Oct 10, 2015
d5a9a4f
merge conflicts
jimmynono-dd Oct 10, 2015
432fed7
Merge pull request #38 from pstrum/angularJames
jimmynono-dd Oct 10, 2015
76b7799
Merge branch 'master' of https://github.com/pstrum/mean-stack-1
Oct 10, 2015
493425f
Update the app.js to show correct information
Oct 10, 2015
1daccc4
Add autoscroll/anchorscroll
Oct 10, 2015
3fc762c
Merge pull request #39 from pstrum/angular-fixes
jimmynono-dd Oct 11, 2015
aee59e5
add ellipses to blog preview, and paragraph breaks
jimmynono-dd Oct 11, 2015
53b0d9e
move pre-wrap to p tags
jimmynono-dd Oct 11, 2015
367ea13
Remove output folder
Oct 11, 2015
575e5bb
Fix merge confict and add ellipses
Oct 11, 2015
c79eb4d
Update delete method to work on form template
Oct 12, 2015
5f5447b
Add ng-show a message when no posts
Oct 12, 2015
cfe18eb
Add Jimmynono edits
Oct 12, 2015
f7bff8e
Merge pull request #40 from pstrum/angularJames
pstrum Oct 12, 2015
a0dc943
Merge branch 'master' into angular-fixes
Oct 12, 2015
d429a12
Remove index.html to public gitignore
Oct 12, 2015
e9b9118
Adjust cache for push
Oct 12, 2015
4a15827
fix untracked files
Oct 12, 2015
e1ef8a8
Add responsive, flexible navigation
Oct 12, 2015
cb03f27
Reverse the order of posts
Oct 12, 2015
3ebec8a
Move ng-cloak outside article in blog-post.html
Oct 12, 2015
e070fd8
Merge pull request #41 from pstrum/angular-fixes
Oct 12, 2015
187c11f
Add flexbox placeholder
Oct 12, 2015
4f98518
Style header layour
Oct 12, 2015
7112313
Merge branch 'header-pagetitle' into blog-post-styling
Oct 12, 2015
c4270ca
initial set up fonts
Oct 12, 2015
4d3ac39
Style blog section
Oct 12, 2015
4c4a61b
Style header layout
Oct 12, 2015
92d380b
Update .gitignore
Oct 12, 2015
d536b3f
Update _blog.scss
Oct 12, 2015
4b58f5d
Add fonts to gulp tasks
Oct 12, 2015
1781893
Update .gitignore
Oct 12, 2015
5cbbf6f
Merge pull request #35 from pstrum/blog-post-styling
pstrum Oct 12, 2015
e50b3aa
Edits to section padding
Oct 12, 2015
e810838
Merge branch 'master' into fonts-gulp
Oct 12, 2015
263110a
Add home and blog links
Oct 12, 2015
9f4bfce
Add functionality to misc links
Oct 12, 2015
f06e1c2
Add hover effect on social links
Oct 12, 2015
6beec0e
Merge pull request #43 from pstrum/fonts-gulp
pstrum Oct 12, 2015
827d8f1
tidy up whitespace
jimmynono-dd Oct 12, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ build/Release
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

# Compiled Public Directory
public/js/
public/styles/
public/views/
16 changes: 16 additions & 0 deletions Gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
gulpfile.js
===========
Rather than manage one giant configuration file responsible
for creating multiple tasks, each task has been broken out into
its own file in gulp/tasks. Any files in that directory get
automatically required below.
To add a new task, simply add a new task file that directory.
gulp/tasks/default.js specifies the default set of tasks to run
when you run `gulp`.
*/

var requireDir = require('require-dir');

// Require all tasks in gulp/tasks, including subfolders
requireDir('./gulp/tasks', { recurse: true });
Binary file removed comps/intelly-blog-III@2x.psd
Binary file not shown.
Binary file removed comps/intelly-blog-post@2x.psd
Binary file not shown.
35 changes: 35 additions & 0 deletions gulp/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var dest = "./public";
var src = './src';

module.exports = {
javascript: {
src: src + '/app/**/*.js',
dest: dest + '/js/',
entryPoint: src + '/app/entry.js',
packedFile: 'packed.js'
},
sass: {
src: src + "/styles/**/*.{sass,scss}",
dest: dest + '/styles/',
settings: {
indentedSyntax: true, // Enable .sass syntax!
}
},
fonts: {
src: src + '/styles/fonts/*',
dest: dest + "/styles/fonts/",
extensions: ['woff2', 'woff', 'eot', 'ttf', 'svg']
},
html: {
src: src + "/app/**/*.html",
dest: dest + "/views/"
},
server: {
serverFile: './server.js'
},
production: {
cssSrc: dest + '/styles/*.css',
jsSrc: dest + '/*.js',
dest: dest
}
};
3 changes: 3 additions & 0 deletions gulp/tasks/default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var gulp = require('gulp');

gulp.task('default', ['sass', 'fonts', 'html', 'webpack', 'watch', 'serve']);
7 changes: 7 additions & 0 deletions gulp/tasks/fonts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var gulp = require("gulp");
var config = require('../config').fonts;

gulp.task('fonts', function() {
return gulp.src(config.src)
.pipe(gulp.dest(config.dest));
});
7 changes: 7 additions & 0 deletions gulp/tasks/html.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var gulp = require("gulp");
var config = require('../config').html;

gulp.task('html', function() {
return gulp.src(config.src)
.pipe(gulp.dest(config.dest));
});
16 changes: 16 additions & 0 deletions gulp/tasks/sass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var gulp = require('gulp');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var handleErrors = require('../util/handleErrors');
var config = require('../config').sass;

gulp.task('sass', function () {
return gulp.src(config.src)
.pipe(sass(config.settings))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.on('error', handleErrors)
.pipe(gulp.dest(config.dest));
});
9 changes: 9 additions & 0 deletions gulp/tasks/serve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var gulp = require('gulp');
var config = require('../config').server;
var server = require("gulp-express");

gulp.task('serve', ['sass', 'fonts', 'html', 'webpack', 'watch'], function() {
server.run([config.serverFile]);

gulp.watch([config.serverFile], [server.run]);
});
8 changes: 8 additions & 0 deletions gulp/tasks/watch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var gulp = require('gulp');
var config = require('../config');

gulp.task('watch', function() {
gulp.watch(config.javascript.src, ['webpack']);
gulp.watch(config.sass.src, ['sass']);
gulp.watch(config.html.src, ['html']);
});
13 changes: 13 additions & 0 deletions gulp/tasks/webpack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var gulp = require('gulp');
var config = require('../config').javascript;
var webpack = require('webpack-stream');

gulp.task('webpack', function(callback) {
return gulp.src(config.entryPoint)
.pipe(webpack({
output: {
filename: config.packedFile
}
}))
.pipe(gulp.dest(config.dest));
});
15 changes: 15 additions & 0 deletions gulp/util/handleErrors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var notify = require("gulp-notify");

module.exports = function() {

var args = Array.prototype.slice.call(arguments);

// Send error to notification center with gulp-notify
notify.onError({
title: "Compile Error",
message: "<%= error %>"
}).apply(this, args);

// Keep gulp from hanging on this task
this.emit('end');
};
39 changes: 39 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "mean-stack-1",
"version": "1.0.0",
"description": "Last week we focussed on JavaScript basics. This week we're going to build up a function web application. You'll be expected to build on knowledge you've already learned (semantic HTML, Sass instead of CSS, in addition to all of the Angular work we'll be doing) and produce a \"production-ready\" blog for your assignment this week.",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/pstrum/mean-stack-1.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/pstrum/mean-stack-1/issues"
},
"homepage": "https://github.com/pstrum/mean-stack-1#readme",
"dependencies": {
"angular": "^1.4.7",
"angular-route": "^1.4.7",
"body-parser": "^1.14.1",
"connect-livereload": "^0.5.3",
"express": "^4.13.3",
"gulp": "^3.9.0",
"gulp-autoprefixer": "^3.0.2",
"gulp-express": "^0.3.5",
"gulp-livereload": "^3.8.1",
"gulp-notify": "^2.2.0",
"gulp-rename": "^1.2.2",
"gulp-run": "^1.6.11",
"gulp-sass": "^2.0.4",
"mongoose": "^4.1.10",
"node-bourbon": "^4.2.3",
"require-dir": "^0.3.0",
"webpack": "^1.12.2",
"webpack-stream": "^2.1.1"
}
}
80 changes: 80 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<!doctype html>
<html class="no-js" lang="en" ng-app="intellyApp">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Intelly</title>
<meta name="description" content="Intelly is your blogging template engine">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href='https://fonts.googleapis.com/css?family=Roboto+Slab:300,400|Ubuntu:400,300,500,700,300italic' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="/styles/main.css">
</head>
<body>
<header>
<h1>intelly</h1>
<nav class="top-navigation">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Pages</a></li>
<li><a href="#/blog-post/">Blog</a></li>
<li><a href="#">Portfolio</a></li>
<li><a href="#">Shortcodes</a></li>
<li><a href="#">Features</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</header>
<main>
<section class="title-description">
<h1>Blog</h1>
<p>The secular cooling that must someday overtake our planet has already gone far indeed with our neighbour. Its physical condition is still largely a mystery, but we know now that even in its equatorial</p>
</section>
<section id="blog-scroll" class="blog">
<div class="breadcrumbs">

<h1><a href="#">Home</a> &middot; <a href="#/blog-post/">Blog</a></h1>
<ul>
<li><a href="#/blog-post/new">New Blog Post</a></li>
<li>Share</li>
<li><span class="icon-twitter"></span></li>
<li><span class="icon-facebook"></span></li>
<li><span class="icon-google-plus"></span></li>
<li><span class="icon-pinterest"></span></li>
</ul>
</div>

<div ng-view>
</div>

</section>
<section class="feature">
<h1>Serene in their assurance of their empire over matter</h1>
<p>No one would have believed in the last years of the nine- teenth century that this world was being watched keenly and closely by intelligences greater than man’s</p>
<a href="contact" class="button-big button-feature">Contact now</a>
<a href="learn" class="button-big button-feature">Learn more</a>
</section>
</main>
<footer>
<div class="footer-top">
<a href="http://maps.google.com" target="_blank">2319 Hilltop Haven Drive<br>Upper Greenwood Lake, NJ 07421</a>
<div class="email-phone">
<a type="tel" href="tel:6624076792">662-407-6792</a><br>
<a type="email" href="mailto:contact@intell.com">contact@intell.com</a>
</div>
<ul class="social-link-footer">
<li><a href="http://twitter.com" target="_blank" class="icon-circle"><span class="footer-icon icon-twitter"></span><span class="icon-text">Follow us</span><span></a></li>
<li><a href="http://facebook.com" target="_blank" class="icon-circle"><span class="footer-icon icon-facebook"></span><span class="icon-text">Like us</span></a></li>
<li><a href="http://linkedin.com" target="_blank" class="icon-circle"><span class="footer-icon icon-linkedin-with-circle"></span><span class="icon-text">Connect</span></a></li>
</ul>
</div>
<ul class="footer-bottom">
<li>&copy; 2014 Intelly LLC</li>
<li><a href="#">Terms of use</a></li>
<li><a href="#">Privacy Policy</a></li>
<li><a href="#">Contact</a></li>
<li><a href="#">Support</a></li>
</ul>
</footer>
<script src="/js/packed.js"></script>
</body>
</html>
107 changes: 107 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// CALL THE PACKAGES WE NEED TO SET UP THE SERVER
// ==============================================
// Require Express Module
var express = require('express');
// Declare the variable 'app', create the Express Application
var app = express();
// bodyParser to expose various factories to create middlewares
var bodyParser = require('body-parser');
// Parses urlencoded bodies; Extend option chooses parsing with qs library
app.use(bodyParser.urlencoded({ extended: true }));
// Parses json
app.use(bodyParser.json());
// Grab the mongoos package
var mongoose = require('mongoose');
// Connect to our local database, named directory auto generated
mongoose.connect('mongodb://localhost/blogs');
// Grab the blog post model
var Blog = require('./src/app/models/blog-post');
// Environment defined port, OR 8000
var port = process.env.PORT || 8000;
// Use built in middleware; pass the directory; use absolute path to directory to serve
app.use(express.static(__dirname + '/public'));
// API ROUTES - How our app responds to client requests
// ==========
// Get instance of Express Router to handle all our routes
var router = express.Router();
// All routes prefixed with /api; add to middleware stack
app.use('/api', router);
// Something to happen every time a request is sent to our API
router.use(function(req, res, next) {
console.log('Something is HAPPENING...');
// make sure we go to the next routes and don't stop here.
next();
});
// Define the home route (accessed at GET localhost:8000/api)
router.get('/', function(req, res) {
res.json({ message: 'YOLO! WELCOME to our API!' });
});
// app.route('/').get(function(req, res) {
// res.sendFile('index.html', {root: __dirname + '/public'});
// });
// To handle multiple routes for the same URI; all req that end in /blog-post
router.route('/blog-post')
// Create a POST (accessed at POST localhost:8000/api/posts)
.post(function(req, res) {
// New instance of the Blog model
var blog = new Blog();
// Set the post title, author, content (comes from request)
blog.title = req.body.title;
blog.author = req.body.author;
blog.content = req.body.content;
// Save the post and check for errors
blog.save(function(err) {
if (err)
res.send(err);
res.json(blog);
});
})
// Get ALL the posts; chaining routes together...
.get(function(req, res) {
Blog.find(function(err, blogs) {
if (err)
res.send(err);
res.json(blogs);
});
});
// To handle all requests that have a :blog_id--accessed through body-parser
router.route('/blog-post/:blog_id')
// Get a post with that id (accessed at GET localhost:8000/api/blog-post/:blog_id)
.get(function(req, res) {
Blog.findById(req.params.blog_id, function(err, blog) {
if (err)
res.send(err);
res.json(blog);
});
})
// Update a post (accessed at PUT localhost:8080/api/blog-post/:blog_id)
.put(function(req, res) {
// Use the blog model to find the post we want
Blog.findById(req.params.blog_id, function(err, blog) {
if (err)
res.send(err);
// Update the post info
blog.title = req.body.title;
blog.author = req.body.author;
blog.content = req.body.content;
// Save the post!
blog.save(function(err) {
if (err)
res.send(err);
res.json(blog);
});
});
})
// Delete a post (accessed at DELETE localhost:8080/api/blog-post/:blog_id)
.delete(function(req, res) {
Blog.remove({
_id: req.params.blog_id
}, function(err, blog) {
if (err)
res.send(err);
res.json(blog);
});
});
// START THE SERVER
app.listen(port);
console.log("Fancy stuff on port " + port);
Loading