Secrets is an application where you can anonymously share your deepest, darkest secrets with the entire internet and have people comment on them. This is totally a good idea where nothing can go wrong.
The best part of this totally viable application is: you have to build it!
-
Make sure you have a database created in Postgres named secrets. You should be able to accomplish this by running
createdb secrets
in your terminal or using your Postgres GUI program (like Postico). -
Check out the hosted finished version of this application here: (https://thawing-waters-37617.herokuapp.com). This should give you clear direction in the necessary features and functionality. Oh, you should also share a secret with us ... please keep it clean. :)
-
Check out the files you already have! You shouldn't have to write any HTML or CSS if using the CSS file available in the
public/stylesheets
folder or the views available inviews
. A lot of the server is also scaffolded out for you already. Take some time to understand what you have already and what you'll need to build. -
A solution can be browsed in the first commit of this repo, direct link here: https://github.com/joedotjs/secrets/tree/ca04e5a8ae65201789fd1c4e7a92f59f325b1a63. Feel free to reference this if you get stuck!
-
Fill in the model definitions for
SecretModel
andCommentModel
indb/models.js
. Both models should really only need atext
column. Keep in mind that comments should reference a secret and you'll probably have to do this using eitherbelongsTo
orhasMany
, or both! -
You should be able to build this application feature-complete with 6 routes:
-
GET /secrets
- This route serves up all secrets in database and renders the
index.html
view. An extra challenge in layering in pagination (prev/next page) but it shouldn't be necessary as the template is written now.
- This route serves up all secrets in database and renders the
-
GET /
- Redirects to
GET /secrets
- Redirects to
-
POST /secrets
- Adds a new secret to the database, then redirects to
GET /secrets
- Adds a new secret to the database, then redirects to
-
GET /secrets/:secretId
- Accesses a secret from the database by its ID, along with comments,
and renders out
secret.html
- Accesses a secret from the database by its ID, along with comments,
and renders out
-
GET /secrets/add
- Renders out the form to add a new secret.
-
POST /secrets/:secretId/comments
- Adds a new comment to a secret, to be seen on the single secret route.
-
-
As mentioned earlier, there is a beyond-the-basics challenge of implementing pagination for the
GET /secrets
route. Look at how thehrefs
inindex.html
for Previous/Next Page links are written. YourGET /secrets
should usereq.query
to enhance your existing query.limit
,offset
in yourwhere
object will be useful to you.