To run in development mode, use:
npm install # Installs dependencies
npm run migrate:dev # Generates sqlite database.
npm run dev # Runs app in development mode.
To run in production mode, use:
npm install # Installs dependencies
npm run build
npm run migrate:prod # Generates postgres database.
npm run start
To run in production mode using docker,
Run the script in the project root directory.
./build --db-pass postgres --db-user postgres --db-name noon-test --port 80 --secret my_secret_ --next-api-endpoint my-website.example.com
You can create a .env in the root project directory and create the following records.
In development mode use:
SECRET=my_secret_
NEXT_PUBLIC_API_ENDPOINT=http://localhost:3000
In production mode use:
SECRET=my_secret_
NEXT_PUBLIC_API_ENDPOINT=mywebsite.example.com
DATABASE_NAME=noon-test
DATABASE_USER=postgres
DATABASE_PASSWORD=my_password
DATABASE_HOST=psql.example.com
The RESTful is integrated within the same codebase as NextJS.
- JWT used for authentication token. The token must be used in each request as a header to identify the user.
Authorization: Bearer <token>
- Passwords are encrypted in Bcrypt.
- sqlite is used as a database in dev mode, postgres in prod.
- ObjectionJS as an ORM
Once logged in, the server responds with a JWT that will be used for identifying the user.
User needs to be signed up first before logging in.
{
"username": "john.doe@example.com",
"password": "hunter2"
}
{
"success": true,
"message": "Successfully logged in.",
"data": "<JWT_TOKEN>"
}
Signs up the user with the provided username, and password.
username
field not need to be an email.
{
"username": "john.doe@example.com",
"password": "hunter2"
}
{
"success": true,
"message": "Successfully signed up."
}
NONE
{
"success": true,
"message": "Successfully logged out."
}
Get all posts.
{
"success": true,
"message": "Successfully found posts.!",
"data": [
{
"id": 1,
"title": "Top 10 Anime Hairstyles",
"imageSrc": "https://images.unsplash.com/photos/9pO3LgH-9-Y",
"description": "Here are the top anime hairstyles according to...",
"favoriteCount": 398
}
]
}
WARNING: To protect this app from illegal images, I decided to only allow images hosted on unsplash.org.
WARNING: User needs to be signed in.
Create a new post.
{
"title": "Top 10 Anime Hairstyles",
"imageSrc": "https://images.unsplash.com/photos/9pO3LgH-9-Y",
"description": "Here are the top anime hairstyles according to..."
}
{
"success": true,
"message": "Successfully found posts!",
"data": {
"id": 1,
"title": "Top 10 Anime Hairstyles",
"imageSrc": "https://images.unsplash.com/photos/9pO3LgH-9-Y",
"description": "Here are the top anime hairstyles according to...",
"favoriteCount": 398
}
}
WARNING: User needs to be signed in.
Returns all favorited posts by the user.
{
"success": true,
"message": "Successfully found posts.!",
"data": [
{
"title": "Top 10 Anime Hairstyles",
"imageSrc": "https://images.unsplash.com/photos/9pO3LgH-9-Y",
"description": "Here are the top anime hairstyles according to...",
"favoriteCount": 398
}
]
}
WARNING: User needs to be signed in.
Adds the post to user favorites.
{
"postId": 1
}
{
"success": true,
"message": "Successfully favorited post."
}
WARNING: User needs to be signed in.
Deletes post from user favorites.
{
"success": true,
"message": "Successfully unfavorited post."
}
- NextJS used as the React framework.
- Used styled-components for styling.
- Redux used for app state management.
Shows the last 100 posts.
How to create a post:
- Create an account
- Login with the account
- Go to the home page
- Fill in the title, image link, and description for the post.
- Submit!
NOTE: Please only use image links hosted on images.unsplash.com I made this decision to stop users from posting undesirable images.
To get a link for an image in,
- Go to unsplash.com
- Right click on the image.
- Select ‘Copy Image Link’
WARNING: User needs to be signed in.
Shows posts that have been favorited by the user.
Shows the login page where the user could sign in or sign up.
Shows the login page where the user could sign in or sign up.