TinyApp is a full stack web application built with Node and Express that allows users to shorten long URLs (à la bit.ly).
- Node.js
- Express
- EJS
- bcryptjs
- cookie-session
- Install all dependencies (using the
npm installcommand). - Run the development web server using the
node express_server.jscommand.
- Authentication Protection
- Permits User to Create, Read, Update, and Delete (CRUD) a simple entity (e.g blog posts, URL shortener).
- Site Header:
-
If a user is logged in, the header shows:
- the user's email
- a logout button
-
If a user is not logged in, the header shows:
- a link to the login page
- a link to the registration page
-
-
GET / -
GET /urls -
GET /urls/new -
GET /urls/:id -
GET /u/:id -
GET /login -
GET /register
-
POST /urls -
POST /urls/:id -
POST /urls/:id/delete -
POST /login -
POST /register -
POST /logout
-
getUserByEmail(formEmail, database): Looks up thedatabasefor a user email that matches theformEmail. Returns the userId of that user from thedatabase. Returnsundefinedif match not found. -
urlsForUser(id, urlDatabase): Looks up theurlDatabasefor the user id that matches theid. Returns the url object, from theurlDatabase, for theid. Returns an empty object if match not found. -
getLoggedInUser(formEmail, formPassword, database): Looks up thedatabasefor a user email that matches theformEmail, then compares and matches the user password to theformPassword. Returns the userId of the user, from thedatabase, who's email and password match. Returnsundefinedif match not found.
-
GET /:- if the user is logged in:
- redirect to
/urls
- redirect to
- if the user is not logged in:
- redirect to
/login
- redirect to
- if the user is logged in:
-
GET /urls:- if user is logged in:
- returns HTML with:
- the site header
- a table of URLs the user has created, each list item containing:
- a short URL
- the short URL's matching long URL
- an edit button which makes a GET request to
/urls/:id - a delete button which makes a POST request to
/urls/:id/delete
- a link to Create a New Short Link which makes a GET request to
/urls/new
- if user is not logged in:
- returns HTML with a relevant error message
- if user is logged in:
-
GET /urls/new:- if user is logged in:
- returns HTML with:
- the site header
- a form which contains:
- a text input field for the original (long) URL
- a submit button which makes a POST request to
/urls
- if user is not logged in:
- redirects to the
/loginpage
- redirects to the
- if user is logged in:
-
GET /urls/:id:- if user is logged in and owns the URL for the given ID:
- returns HTML with:
- the site header
- the short URL (for the given ID)
- a form which contains:
- the corresponding long URL
- an update button which makes a POST request to
/urls/:id
- if a URL for the given ID does not exist:
- returns HTML with a relevant error message
- if user is not logged in:
- returns HTML with a relevant error message
- if user is logged in but does not own the URL with the given ID:
- returns HTML with a relevant error message
- if user is logged in and owns the URL for the given ID:
-
GET /u/:id:- if URL for the given ID exists:
- redirects to the corresponding long URL
- if URL for the given ID does not exist:
- return HTML with a relevant error message
- if URL for the given ID exists:
-
GET /login:- if user is logged in:
- redirects to
/urls
- redirects to
- if user is not logged in:
- returns HTML with:
- a form which contains:
- input fields for email and password
- a login button which makes a POST request to
/login
- if user is logged in:
-
GET /register:- if user is logged in:
- redirects to
/urls
- redirects to
- if user is not logged in:
- returns HTML with:
- a form which contains:
- input fields for email and password
- a register button which makes a POST request to
/register
- if user is logged in:
-
POST /urls:- if user is logged in:
- generates a short URL, saves it, and associates it with the user
- redirects to
/urls/:id, where:idmatches the ID of the newly saved URL
- if user is not logged in:
- returns HTML with a relevant error message
- if user is logged in:
-
POST /urls/:id:- if user is logged in and owns the URL for the given ID:
- updates the URL
- redirects to
/urls
- if user is not logged in:
- returns HTML with a relevant error message
- if user is logged in but does not own the URL of the given ID:
- returns HTML with a relevant error message
- if user is logged in and owns the URL for the given ID:
-
POST /urls/:id/delete:- if user is logged in and owns the URL for the given ID:
- deletes the URL
- redirects to
/urls
- if user is not logged in:
- returns HTML with a relevant error message
- if user is logged in but does not own the URL of the given ID:
- returns HTML with a relevant error message
- if user is logged in and owns the URL for the given ID:
-
POST /login:- if email and password params match an existing user:
- sets a cookie
- redirects to
/urls
- if email and password params do not match an existing user:
- returns HTML with a relevant error message
- if email and password params match an existing user:
-
POST /register:- if email or password are empty:
- returns HTML with a relevant error message
- if email already exists:
- returns HTML with a relevant error message
- otherwise:
- creates a new user
- encrypts the new user's password with
bcrypt - sets a cookie
- redirects to
/urls
- if email or password are empty:
-
POST /logout:- deletes cookie
- redirects to
/login




