Skip to content

Commit e9c7e4c

Browse files
committed
db updated to online server
1 parent 192e3b9 commit e9c7e4c

File tree

3,392 files changed

+374114
-17
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,392 files changed

+374114
-17
lines changed

app.js

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const express = require("express");
44
const bodyParser = require("body-parser");
55
const ejs = require("ejs");
66
const _ = require("lodash");
7+
const mongoose = require("mongoose");
78

89
const homeStartingContent = "Lacus vel facilisis volutpat est velit egestas dui id ornare. Semper auctor neque vitae tempus quam. Sit amet cursus sit amet dictum sit amet justo. Viverra tellus in hac habitasse. Imperdiet proin fermentum leo vel orci porta. Donec ultrices tincidunt arcu non sodales neque sodales ut. Mattis molestie a iaculis at erat pellentesque adipiscing. Magnis dis parturient montes nascetur ridiculus mus mauris vitae ultricies. Adipiscing elit ut aliquam purus sit amet luctus venenatis lectus. Ultrices vitae auctor eu augue ut lectus arcu bibendum at. Odio euismod lacinia at quis risus sed vulputate odio ut. Cursus mattis molestie a iaculis at erat pellentesque adipiscing.";
910
const aboutContent = "Hac habitasse platea dictumst vestibulum rhoncus est pellentesque. Dictumst vestibulum rhoncus est pellentesque elit ullamcorper. Non diam phasellus vestibulum lorem sed. Platea dictumst quisque sagittis purus sit. Egestas sed sed risus pretium quam vulputate dignissim suspendisse. Mauris in aliquam sem fringilla. Semper risus in hendrerit gravida rutrum quisque non tellus orci. Amet massa vitae tortor condimentum lacinia quis vel eros. Enim ut tellus elementum sagittis vitae. Mauris ultrices eros in cursus turpis massa tincidunt dui.";
@@ -16,10 +17,35 @@ app.set('view engine', 'ejs');
1617
app.use(bodyParser.urlencoded({extended: true}));
1718
app.use(express.static("public"));
1819

19-
const posts = [];
20+
mongoose.connect("mongodb+srv://admin-gabryel:[email protected]/blogsiteDB");
21+
// mongoose.connect("mongodb://localhost:27017/blogsiteDB");
22+
23+
const postSchema = {
24+
postTitle: String,
25+
postContent: String
26+
}
27+
28+
const Post = mongoose.model("Post", postSchema);
29+
30+
const post1 = {
31+
postTitle: "Home",
32+
postContent: homeStartingContent
33+
}
2034

2135
app.get("/", function(req, res){
22-
res.render("home", {homeStartingContent: homeStartingContent, posts: posts});
36+
Post.find({}, function(err, posts){
37+
if (!err) {
38+
if (posts.length === 0) {
39+
Post.create(post1);
40+
res.redirect("/");
41+
} else {
42+
res.render("home", {posts: posts});
43+
}
44+
} else {
45+
console.log(err);
46+
}
47+
})
48+
//res.render("home", {homeStartingContent: homeStartingContent, posts: posts});
2349
})
2450

2551
app.get("/about", function(req, res){
@@ -35,23 +61,25 @@ app.get("/compose", function(req, res){
3561
})
3662

3763
app.get("/posts/:postName", function(req, res){
38-
const postName = req.params.postName;
39-
posts.forEach(function(element){
40-
if (_.lowerCase(postName) === _.lowerCase(element.postTitle)) {
41-
res.render("post", {postTitle: element.postTitle, postContent: element.postContent});
42-
} else {
43-
return
44-
}
45-
})
46-
64+
let postName = req.params.postName;
65+
Post.findOne({postTitle: postName}, function(err, foundPost){
66+
res.render("post", {postTitle: foundPost.postTitle, postContent: foundPost.postContent});
67+
});
68+
// posts.forEach(function(element){
69+
// if (_.lowerCase(postName) === _.lowerCase(element.postTitle)) {
70+
// res.render("post", {postTitle: element.postTitle, postContent: element.postContent});
71+
// } else {
72+
// return
73+
// }
74+
// })
4775
})
4876

4977
app.post("/compose", function(req, res){
50-
const post = {
78+
const new_post = {
5179
postTitle: req.body.postTitle,
5280
postContent: req.body.postContent
5381
}
54-
posts.push(post);
82+
Post.create(new_post);
5583
res.redirect("/")
5684
})
5785

node_modules/.bin/fxparser

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/fxparser.cmd

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/fxparser.ps1

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/uuid

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/uuid.cmd

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/uuid.ps1

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@aws-crypto/ie11-detection/CHANGELOG.md

Lines changed: 70 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)