Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nav bar fix #511

Closed
wants to merge 189 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
189 commits
Select commit Hold shift + click to select a range
ad1dd33
Updated Readme
Loo-Ashworth Jun 12, 2023
71cfbe6
Merge pull request #1 from Loo-Ashworth/ReadmeInitial
adrianHards Jun 12, 2023
3424dce
basic links to navigate site
adrianHards Jun 12, 2023
faa41bc
add basic seed file and structure
adrianHards Jun 12, 2023
f7a6855
es6 refactor
adrianHards Jun 12, 2023
039134e
Cypress version updated
Joecunliffe98 Jun 12, 2023
7bb1db2
Merge pull request #2 from Loo-Ashworth/seed
emmadavids Jun 12, 2023
a647b68
added message to inform user of login
emmadavids Jun 13, 2023
c3811b9
merge with main
adrianHards Jun 13, 2023
b6ae009
Merge pull request #3 from Loo-Ashworth/cypress_V2
adrianHards Jun 13, 2023
d3e1f17
updating config stuff
emmadavids Jun 13, 2023
637292e
add additional post unit tests
adrianHards Jun 13, 2023
095324b
refactored post unit tests
adrianHards Jun 13, 2023
c83287e
remove posts reverse test from unit test
adrianHards Jun 13, 2023
436277c
use class not text to select new post link
adrianHards Jun 13, 2023
c36ed9d
posts show in reverse order
adrianHards Jun 13, 2023
7af047a
remove commented out test
adrianHards Jun 13, 2023
36b1188
Merge pull request #5 from Loo-Ashworth/posts
adrianHards Jun 13, 2023
b6dadfa
added user logic
emmadavids Jun 13, 2023
c065748
merge with main
emmadavids Jun 13, 2023
e12a696
fixed config typo
emmadavids Jun 13, 2023
8be0875
fixed test typo
emmadavids Jun 13, 2023
1b082ce
Merge pull request #6 from Loo-Ashworth/emmad
emmadavids Jun 13, 2023
b33ce83
fix post model and unit tests
adrianHards Jun 13, 2023
d13a4ee
update seed file
adrianHards Jun 13, 2023
28171ce
remove unnecessary imports
adrianHards Jun 13, 2023
586bb07
unique post and user id for a like
adrianHards Jun 13, 2023
2489a4e
Merge pull request #7 from Loo-Ashworth/add-user-to-post
lisaoausb Jun 13, 2023
014b475
danger do not use this code
emmadavids Jun 13, 2023
e2f73f6
likes are unique and can be toggled by user for a specific post
adrianHards Jun 13, 2023
461c98c
modify eslint rules
adrianHards Jun 13, 2023
0529c5b
refactor
adrianHards Jun 13, 2023
d315867
update seed file to drop Likes; add username to User
adrianHards Jun 14, 2023
6b974dc
update seed file to include username
adrianHards Jun 14, 2023
02eeec3
comment out username
adrianHards Jun 14, 2023
a640ca5
remove username
adrianHards Jun 14, 2023
c6d50e4
show liked by users on hover
adrianHards Jun 14, 2023
1fb1f67
fixed controller issue.
emmadavids Jun 14, 2023
5c1a8ea
Merge pull request #8 from Loo-Ashworth/likes
lisaoausb Jun 14, 2023
1338f71
fix post unit tests for multiple posts
adrianHards Jun 14, 2023
4831034
add unit tests for likes
adrianHards Jun 14, 2023
406b4f9
add unit tests for likes
adrianHards Jun 14, 2023
11795a0
added error handling for duplicate email
emmadavids Jun 14, 2023
d6f69f4
commenting out failing test
emmadavids Jun 14, 2023
aa21c24
Merge pull request #9 from Loo-Ashworth/likes-unit-tests
adrianHards Jun 14, 2023
e8ea256
Merge branch 'main' of https://github.com/Loo-Ashworth/acebook-poke i…
emmadavids Jun 14, 2023
9eb3ba5
fixed session controller pw logic
emmadavids Jun 14, 2023
fa59ae8
Update users.js
adrianHards Jun 14, 2023
1e64167
Merge branch 'main' of https://github.com/Loo-Ashworth/acebook-poke i…
emmadavids Jun 14, 2023
44b8684
cloudinary setup
emmadavids Jun 14, 2023
6da1bed
wahh
emmadavids Jun 14, 2023
b4ab720
Merge pull request #11 from Loo-Ashworth/emmad
adrianHards Jun 14, 2023
08f319a
setup friends page, friends model, routes and controller
adrianHards Jun 14, 2023
72715e1
testing in progress
emmadavids Jun 14, 2023
381a678
add ability to add a friend
adrianHards Jun 14, 2023
45fa498
Refactored E2E Specs into Site Object
Loo-Ashworth Jun 14, 2023
ce672d8
pending friendships can be accepted or rejected
adrianHards Jun 14, 2023
7b2ef39
Adjusted to Include Username Entry
Loo-Ashworth Jun 14, 2023
00401d0
list pending friendships
adrianHards Jun 14, 2023
3f1adb9
add link to friends; show sent friend requests
adrianHards Jun 14, 2023
5185f26
send a friend request
adrianHards Jun 15, 2023
3196e48
show username of poster
adrianHards Jun 15, 2023
4f7b9bc
prevent users from befriending themselves
adrianHards Jun 15, 2023
0f363bf
refactor stylesheets
adrianHards Jun 15, 2023
9c4995e
wrote some more tests for user
emmadavids Jun 15, 2023
200d7e8
added tests for user
emmadavids Jun 15, 2023
65a82d3
small change to email whitespace test
emmadavids Jun 15, 2023
1f0d766
resolved conflict
emmadavids Jun 15, 2023
8b7653a
Moved File Locations to Improve Cypress Run
Loo-Ashworth Jun 15, 2023
b42b21c
Merge pull request #12 from Loo-Ashworth/befriend
Joecunliffe98 Jun 15, 2023
0d81155
Merge branch 'main' into e2e_refactor
Loo-Ashworth Jun 15, 2023
1ce65f8
Refresh Directories
Loo-Ashworth Jun 15, 2023
bdf6a3b
Deleted pageClassTestSpec.js
Joecunliffe98 Jun 15, 2023
4083acb
user stays logged in even after encountering bug
adrianHards Jun 15, 2023
59b93fa
Added Can See Likes Count On Post Test - Fixed formatting issue with …
Joecunliffe98 Jun 15, 2023
bf5ad09
Moved likes test file to redundant
Joecunliffe98 Jun 15, 2023
0c62c8c
Added test for likes when multiple posts are made
Joecunliffe98 Jun 15, 2023
c33d202
add a drop db script
adrianHards Jun 15, 2023
74d73cc
Merge pull request #14 from Loo-Ashworth/session-persistance-bug
Loo-Ashworth Jun 15, 2023
cbb99c2
render new message when validation error
adrianHards Jun 15, 2023
7fc12a2
shift enter no longer opens a new window
adrianHards Jun 15, 2023
d19e198
Test added for seeing posts in reverse order & multiple posts like count
Joecunliffe98 Jun 15, 2023
98a37f2
add timestamps to posts
adrianHards Jun 15, 2023
3d1ec38
format timestamps
adrianHards Jun 15, 2023
7c2690d
added functionality to write comments under a post, also displays aut…
lisaoausb Jun 15, 2023
8781b97
refactor posts page
adrianHards Jun 15, 2023
00aa506
Users can see posts in reverse order moved to redundant folder
Joecunliffe98 Jun 15, 2023
62a2a7a
Added logout feature to site object model & Added user can like anoth…
Joecunliffe98 Jun 15, 2023
247490e
add message when successfully signed in
adrianHards Jun 15, 2023
a41e049
add message when successfully signed out
adrianHards Jun 15, 2023
93cfa3a
refactor drop
adrianHards Jun 15, 2023
4a4a36e
added tests for comments
lisaoausb Jun 15, 2023
1eb29ec
Added shouldContain method, changed likePost method so a post ID can …
Joecunliffe98 Jun 15, 2023
f2eded4
trying to resolve error when posting spaces as a comment
lisaoausb Jun 15, 2023
de74aa5
Merge pull request #15 from Loo-Ashworth/render-new-on-error
lisaoausb Jun 15, 2023
1db95d1
resolved merge conflicts
lisaoausb Jun 15, 2023
849a3c6
rewrote tests - some need review still broken
emmadavids Jun 15, 2023
a1a904a
reset files to how they were to find why route is not going back to p…
lisaoausb Jun 15, 2023
7f9ec3a
playing with cloudinary configg
emmadavids Jun 15, 2023
ef38e80
playing with cloudinary config part 2
emmadavids Jun 15, 2023
32f1ad9
Merge branch 'main' of into testing-user
emmadavids Jun 15, 2023
2f34dfe
enforce unique username and email
adrianHards Jun 16, 2023
d5b4243
refactor notes
adrianHards Jun 16, 2023
358ac57
cloudinary in progress
emmadavids Jun 16, 2023
ec15707
let a user sign out
adrianHards Jun 16, 2023
56a151c
fix sign up bug
adrianHards Jun 16, 2023
296185d
Merge pull request #16 from Loo-Ashworth/testing-user-adrian
emmadavids Jun 16, 2023
f87ba58
Merge pull request #13 from Loo-Ashworth/testing-user
adrianHards Jun 16, 2023
5b9dcee
error message displays when people enter spaces only
lisaoausb Jun 16, 2023
fc3ee34
comment functionality
lisaoausb Jun 16, 2023
97a7684
cloudinary still in progress..
emmadavids Jun 16, 2023
a31404a
cloudinary still in progress
emmadavids Jun 16, 2023
12d8838
Redundant folder removed
Joecunliffe98 Jun 16, 2023
7211510
Create main.yml
adrianHards Jun 16, 2023
ea3dfe4
Merge pull request #17 from Loo-Ashworth/comments
adrianHards Jun 16, 2023
8f45838
merge with main
adrianHards Jun 16, 2023
6564ff9
Merge remote-tracking branch 'origin' into e2e_refactor
Joecunliffe98 Jun 16, 2023
f7a2b73
Site object model changed to reflect new posts page
Joecunliffe98 Jun 16, 2023
bce2d87
Merge pull request #20 from Loo-Ashworth/e2e_refactor
Loo-Ashworth Jun 16, 2023
d6ed7b2
merge with main
adrianHards Jun 16, 2023
8a0fcb7
Merge pull request #19 from Loo-Ashworth/github-action
Loo-Ashworth Jun 16, 2023
0524d8d
cloudinary tinkering
emmadavids Jun 16, 2023
0e5f9ae
tinkering
emmadavids Jun 16, 2023
c5814c2
remove images
adrianHards Jun 16, 2023
ade1eb0
resolve merge conflict
adrianHards Jun 16, 2023
ac432d4
update package lock
adrianHards Jun 16, 2023
956cde8
hide api keys
adrianHards Jun 16, 2023
da1483d
Added Performance Testing
Loo-Ashworth Jun 16, 2023
1a5d302
multer woes
adrianHards Jun 16, 2023
4576d7b
Merge pull request #21 from Loo-Ashworth/performance
Lmason14 Jun 16, 2023
b698686
finally upload to cloudinary
adrianHards Jun 16, 2023
699b9e6
hide api keys
adrianHards Jun 16, 2023
ac17911
merge with main
adrianHards Jun 16, 2023
a9f6740
image is null
adrianHards Jun 16, 2023
1f84bc0
remove flash
adrianHards Jun 16, 2023
00ba44b
Merge pull request #22 from Loo-Ashworth/cloudinary-adrian
adrianHards Jun 16, 2023
3331d43
add photos to posts
adrianHards Jun 16, 2023
5ae9453
change to input
adrianHards Jun 16, 2023
a7ce750
Merge pull request #23 from Loo-Ashworth/add-photo-to-post
Loo-Ashworth Jun 16, 2023
add8919
break index into partials
adrianHards Jun 18, 2023
d52a910
ajax for posts
adrianHards Jun 18, 2023
78ce04f
abstract away code from the posts controller
adrianHards Jun 19, 2023
a688b85
abstract away code from other controllers
adrianHards Jun 19, 2023
6a855e6
refactor posts to ajax comment
adrianHards Jun 19, 2023
b8e6fcc
refactor partials
adrianHards Jun 19, 2023
b316f86
move ajax js in to public folder
adrianHards Jun 19, 2023
f59b761
ajax working for comments
adrianHards Jun 19, 2023
52ed202
add id to new post to enable comments on that post
adrianHards Jun 19, 2023
29aec5e
ajax comments
adrianHards Jun 19, 2023
c9ce8eb
remove unncessary files
adrianHards Jun 19, 2023
7149e84
new posts aren't pokeable
adrianHards Jun 19, 2023
41cfbf4
ajax of likes works on existing posts
adrianHards Jun 19, 2023
8cb72bd
ajax of likes for a new post
adrianHards Jun 19, 2023
a5a7ca9
pass unit tests
adrianHards Jun 19, 2023
9a98c3c
added edit/delete functionality to post
emmadavids Jun 19, 2023
0e512bf
create new post
adrianHards Jun 19, 2023
800005d
refactor code
adrianHards Jun 19, 2023
d684d12
refactor ajax js code into diff files
adrianHards Jun 20, 2023
6e991fd
prettier
adrianHards Jun 20, 2023
333bb03
redirect to sign in if not before visiting posts
adrianHards Jun 20, 2023
e01c5a7
Merge pull request #27 from Loo-Ashworth/editdeletepost
emmadavids Jun 20, 2023
b1340a8
added confirm msg
emmadavids Jun 20, 2023
125d768
reset form on submit
adrianHards Jun 20, 2023
74d097f
remove lines from e2e
adrianHards Jun 20, 2023
bdcb3b3
add user who liked post even if new post
adrianHards Jun 20, 2023
fd824fe
failing e2e edits
adrianHards Jun 20, 2023
0925666
fix handler and refactor target
adrianHards Jun 20, 2023
8cbe5ed
remove spacing around 0
adrianHards Jun 20, 2023
191e831
passing 4 and 7
adrianHards Jun 20, 2023
f1022d6
passing all tests
adrianHards Jun 20, 2023
bf80e02
merge edit and delete
adrianHards Jun 20, 2023
7aac94d
Merge pull request #28 from Loo-Ashworth/editdeletepost
adrianHards Jun 20, 2023
c5a7356
merge with main
adrianHards Jun 20, 2023
f7c98c5
add delete
adrianHards Jun 20, 2023
f846ab3
Merge pull request #25 from Loo-Ashworth/partials
adrianHards Jun 20, 2023
4c3746b
add photos to posts and user
adrianHards Jun 20, 2023
9fc1ced
Merge pull request #30 from Loo-Ashworth/avatar
lisaoausb Jun 20, 2023
f80f821
show modal on edit
adrianHards Jun 20, 2023
e0e8ef3
add id to comment
adrianHards Jun 20, 2023
a0b02ee
added delete button to comments
emmadavids Jun 20, 2023
d520a1b
unable to pass updated message
adrianHards Jun 20, 2023
c0cdb35
ajax edit a post
adrianHards Jun 20, 2023
d94440d
refactor js code
adrianHards Jun 20, 2023
2677c05
Merge pull request #31 from Loo-Ashworth/delete-fix
Loo-Ashworth Jun 21, 2023
85dc2fb
Merge branch 'main' into edit-delete-comment
emmadavids Jun 21, 2023
3f4adf1
deleted commented out code
emmadavids Jun 21, 2023
4043d28
add delete button to comment
emmadavids Jun 21, 2023
cf461a9
testing tests
emmadavids Jun 21, 2023
fb92904
added burger menu
emmadavids Jun 21, 2023
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
39 changes: 14 additions & 25 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
{
"env": {
"commonjs": true,
"es6": true,
"node": true,
"jest/globals": true,
"cypress/globals": true
},
"extends": [
"eslint:recommended",
"plugin:node/recommended"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2022
},
"plugins": [
"cypress",
"jest",
"node"
],
"rules": {
}
"env": {
"browser": true,
"es2021": true
},
"extends": ["eslint:recommended", "plugin:react/recommended"],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["react"],
"rules": {
"no-useless-catch": "off",
"no-undef": "off"
}
}
33 changes: 33 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Continuous Integration
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build-and-test:
runs-on: ubuntu-22.04

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Start MongoDB
uses: supercharge/mongodb-github-action@1.8.0
with:
mongodb-version: 6.0

- name: Install dependencies
run: npm install

- name: Start server
run: npm run start:test &

- name: Run unit tests
run: npm run test:unit

- name: Cypress run
uses: cypress-io/github-action@v5
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ typings/
# cypress.io
cypress/screenshots
cypress/videos

.DS_Store
94 changes: 94 additions & 0 deletions K6/K6CreateAccount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import http from "k6/http";
import { htmlReport } from "https://raw.githubusercontent.com/benc-uk/k6-reporter/main/dist/bundle.js";

// TEST OPTIONS EXPLANATION:
// executor: https://k6.io/docs/using-k6/scenarios/#scenario-executors
// rate 1 timeUnit 1 Means rate: 1, timeUnit: '1s' means "try to start 1 iteration every second"
// duration: Run test for this duration
// maxVus: Stop test if this is reached
// Pre-allocated vus loads a number of iterations into memory before the test starts to ensure consistent reporting

export const options = {
scenarios: {
constant_request_rate: {
executor: "constant-arrival-rate",
rate: 5,
timeUnit: "1s",
duration: "15s",
preAllocatedVUs: 20,
maxVUs: 1000,
},
},
};

// Specify Key URLS to HTTP Request Here:
const home = "http://127.0.0.1:3030/";
//const home = 'https://acebook-main.onrender.com/';
const signUp = home + "users/new";
const signIn = home + "sessions/new";
const usersUrl = home + "users/";
const newPost = home + "posts/new";

const headers = {
"Content-Type": "application/x-www-form-urlencoded",
};

// THIS IS THE SCENARIO THAT WILL BE EXECUTED PER ITERATION

export default function () {
// Helper Method to Make a Random String
function generateRandomString() {
const characters = "abcdefghijklmnopqrstuvwxyz0123456789";
let randomString = "";
for (let i = 0; i < 8; i++) {
randomString += characters[Math.floor(Math.random() * characters.length)];
}
return randomString;
}

// SCENARIO:
// 1) Visit Home
// 2) Visit signUp
// 3) Create Account
// 4) Log In

// Create Random user
let randUser = `user${generateRandomString()}`;
let body =
"username=" +
randUser +
"%40test.com&email=" +
randUser +
"%40test.com&password=$" +
randUser;

// Sign Up
http.get(home);
http.get(signUp);
const thisPost = http.post(usersUrl, body, { headers: headers });

// Account Creation Reporting Block
if (thisPost.status == "200") {
console.log("Response Code:", thisPost.status);
console.log(`${randUser} Account Created`);
} else {
console.log("Response Code:", thisPost.status);
console.log(`${randUser} Account Creation Failed`);
}

// // Sign In
// http.get(newPost);

// // Make a Post
// http.get(newPost);
}

// THIS FUNCTION GENERATES A SUMMARY REPORT AS HTML
export function handleSummary(data) {
return {
"K6/CreateAccountSummary.html": htmlReport(data),
};
}

// TO EXECUTE TEST: k6 run K6CreateAccount.js
// TO EXECUTE WITH OPTIONAL CSV DATA: 6 run --out csv=<CSVFILENAME>.csv K6CreateAccount.js
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
# Rules For Pushing

Before making a pull request. From your branch:

1. stage any changes git add . & git commit -m "meaningful message"
2. git checkout main
3. update your local main git pull origin main5
4. go back to your branch git checkout branch-name
5. merge your branch with main git merge main
6. resolve any conflicts locally; speak with the person who wrote the conflicting code if necessary
7. repeat step 1
8. open a PR git push origin branch-name

To add, if you ever want to make your branch available for everyone else, simply:

- git push origin branch-name just don’t open up a PR after, and everyone can then check out your branch

# Collaborator User Names

- Louis - Loo-Ashworth
- Adrian - adrianHards
- Laura - Lmason14
- Joe - Joecunliffe98
- Terry - terenceroach
- Lisa - lisaoausb
- Emma - emmadavids
- Joan -JoanKalanzi

# Acebook

This is a Node.js template for the Acebook engineering project.
Expand All @@ -14,7 +42,7 @@ It uses:

## Card wall

REPLACE THIS TEXT WITH A LINK TO YOUR CARD WALL
<a href="https://miro.com/app/board/uXjVM_xqOSQ=/"> Miro Board</a>

## Quickstart

Expand Down Expand Up @@ -46,7 +74,7 @@ REPLACE THIS TEXT WITH A LINK TO YOUR CARD WALL
brew tap mongodb/brew
brew install mongodb-community@5.0
```
*Note:* If you see a message that says `If you need to have mongodb-community@5.0 first in your PATH, run:`, follow the instruction. Restart your terminal after this.
_Note:_ If you see a message that says `If you need to have mongodb-community@5.0 first in your PATH, run:`, follow the instruction. Restart your terminal after this.
7. Start MongoDB
```
brew services start mongodb-community@5.0
Expand Down Expand Up @@ -93,3 +121,11 @@ Some people occasionally experience MongoDB connection errors when running the t
- Check that it's running using `brew services list`

If you have issues that are not resolved by these tips, please reach out to a coach and, once the issue is resolved, we can add a new tip!

Requirements
Bcrypt - for pw hashing
Validator
Cloudinary
Multer
dotenv
method-override
52 changes: 39 additions & 13 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@ const cookieParser = require("cookie-parser");
const logger = require("morgan");
const session = require("express-session");
const methodOverride = require("method-override");
require("dotenv").config();
const hbs = require("hbs");

const homeRouter = require("./routes/home");
const postsRouter = require("./routes/posts");
const sessionsRouter = require("./routes/sessions");
const usersRouter = require("./routes/users");
const likesRouter = require("./routes/likes");
const commentsRouter = require("./routes/comments");
const friendsRouter = require("./routes/friends");

const app = express();

// view engine setup
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "hbs");
hbs.registerPartials(path.join(__dirname, "views/partials"));

app.use(logger("dev"));
app.use(express.json());
Expand All @@ -36,15 +41,13 @@ app.use(
})
);

// clear the cookies after user logs out
app.use((req, res, next) => {
if (req.cookies.user_sid && !req.session.user) {
res.clearCookie("user_sid");
}
next();
});

// middleware function to check for logged-in users
const sessionChecker = (req, res, next) => {
if (!req.session.user && !req.cookies.user_sid) {
res.redirect("/sessions/new");
Expand All @@ -53,26 +56,49 @@ const sessionChecker = (req, res, next) => {
}
};

// route setup
app.use((req, res, next) => {
if (req.session.user) {
res.locals.user = req.session.user;
}
next();
});

app.post("/signup", async (req, res) => {
try {
if (req.body.password !== req.body.password2) {
throw new Error("Passwords don't match. Try again.");
}

const user = new User(req.body);
await user.save();
} catch (error) {
res.status(400).send(error);
}
});

app.use("/", homeRouter);
app.use("/posts", sessionChecker, postsRouter);
app.use("/sessions", sessionsRouter);
app.use("/users", usersRouter);
app.use("/likes", likesRouter);
app.use("/comments", commentsRouter);
app.use("/friends", friendsRouter);

// catch 404 and forward to error handler
app.use((req, res, next) => {
next(createError(404));
});

// error handler
app.use((err, req, res) => {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get("env") === "development" ? err : {};
app.use((err, req, res, next) => {
req.session.save((err2) => {
if (err2) {
return next(err2);
}
res.locals.message = err.message;
res.locals.error = req.app.get("env") === "development" ? err : {};

// render the error page
res.status(err.status || 500);
res.render("error");
res.status(err.status || 500);
res.render("error");
});
});

module.exports = app;
2 changes: 2 additions & 0 deletions bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ var mongoDbUrl = process.env.MONGODB_URL || "mongodb://0.0.0.0/acebook";
mongoose.connect(mongoDbUrl, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false,
});

var db = mongoose.connection;
Expand Down
Loading