Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed a bug when routing the /admin

  • Loading branch information...
commit ef070076d8aacee14401e42766f43b6fb2162477 1 parent e63b560
@pedrofranceschi pedrofranceschi authored
Showing with 14 additions and 14 deletions.
  1. +12 −12 blogode.js
  2. +1 −1  lib/database.js
  3. +1 −1  views/posts/show.ejs
View
24 blogode.js
@@ -29,18 +29,6 @@ app.get("/", function(req, res){
});
});
-app.get("/:id", function(req, res){
- // return an specific post (by ID)
-
- posts.getPost(req.param('id'), function(post) {
- comments.getCommentsOfPost(req.param('id'), function(comments){
- res.render('posts/show', {
- locals: { 'post': post, 'comments': comments }
- });
- });
- });
-});
-
app.get("/admin", function(req, res){
// return admin panel
@@ -164,5 +152,17 @@ app.get('/admin/posts/destroy/:id', function(req, res) {
});
});
+app.get("/:id", function(req, res){
+ // return an specific post (by ID)
+
+ posts.getPost(req.param('id'), function(post) {
+ comments.getCommentsOfPost(req.param('id'), function(comments){
+ res.render('posts/show', {
+ locals: { 'post': post, 'comments': comments }
+ });
+ });
+ });
+});
+
app.listen(3000);
console.log("Server on port %s", app.address().port);
View
2  lib/database.js
@@ -23,7 +23,7 @@ exports.getDatabaseConnection = function(callback) {
exports._createTables = function(mysql_client, callback) {
mysql_client.query("CREATE TABLE IF NOT EXISTS posts (id INT PRIMARY KEY AUTO_INCREMENT, user_id INT, title VARCHAR(200), body TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);")
mysql_client.query("CREATE TABLE IF NOT EXISTS users (id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(100), description VARCHAR(500), email VARCHAR(100), username VARCHAR(100), password VARCHAR(100), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);")
- mysql_client.query("CREATE TABLE IF NOT EXISTS comments (id INT PRIMARY KEY AUTO_INCREMENT, in_reply_to_id INT, post_id INT, author_name VARCHAR(100), author_email VARCHAR(100), comment TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);")
+ mysql_client.query("CREATE TABLE IF NOT EXISTS comments (id INT PRIMARY KEY AUTO_INCREMENT, post_id INT, author_name VARCHAR(100), author_email VARCHAR(100), comment TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);")
callback();
}
View
2  views/posts/show.ejs
@@ -2,7 +2,7 @@
<p>by <%= post.user_name %></p>
<p><%- unescape(post.body) %></p>
-<h1>Comments</h1>
+<h2>Comments</h2>
<% for (var i=0; i < comments.length; i++) { %>
<h4><%= comments[i].author_name %></h4>
Please sign in to comment.
Something went wrong with that request. Please try again.