Skip to content

A simple PostgreSQL Express React Node (PERN) full-stack app for posting and viewing Memes.

License

Notifications You must be signed in to change notification settings

soham0-0/meme-stream-app

Repository files navigation

meme-stream-app

📚 General info

Directory Structure

  • The directory structure of this repo has been kept in accordance to the heroku deployment policies.
  • The Front-End code is present in ./client/ directory.
  • The Back-End code is present in the root directory of the repository.
  • The Scripts and Dockerfile are also present in the root directory itself, as per the buildout assesment instructions

Backend

  • PostgreSQL needs to be installed and running - I installed it from the debian repository and configured in psql
  • Swagger used to test the backend before frontend was available
  • Postgresql shell commands: \l list all databases. \c database1 connect to database1. \dt inspect tables. \q to quit.

Frontend

  • React frontend includes a form component with name, caption and url input fields.
  • Create React App was used for the frontend.

📷 Screenshots

  • Swagger UI Swagger screenshot

  • App Front-End Frontend screenshot

📶 Technologies - Backend

📶 Technologies - Frontend

💾 Setup

Docker - Backend

  • Install Docker on your device.
  • Run docker build -t xmeme_app .
  • Run docker run -d --net="host" xmeme_app.
  • Now your backend server is running on port 8081 and swagger ui on port 8080.

Local - Backend (For Ubuntu 18.04 LTS)

  • Give executable permissions to the all the scripts as $ chmod +x <script_name>
  • Run insall.sh to install and setup the package dependencies eg, node, npm, postgresql.
  • Run server_run to install the npm dependencies and run the server for the first time.
  • Now every time you want to run the server run npm run dev

Local - Frontend

  • cd client/
  • Run yarn install to install all the project dependencies
  • Run yarn start to start development server.

💻 Code Examples - Backend

const validateImageUrl = async (url) => {
    let isImage;

    // Fetching for checking for existance of resource and header Content-Type : image/*
    await fetch(url)
        .then((response) => {
            if(response.status === 200 && ((response.headers.raw()['content-type'][0]).match(/(image)+\//g)).length != 0){
                isImage = true;        
            } else {
                isImage = false;
            }
        }).catch((error) => {
            isImage = false;
        });

    // Requesting Size of the image just in case headers were wrong
    await requestImageSize(url)
        .then(size => {
            isImage = true;
        })
        .catch(err => {
            isImage = isImage || false;
        });
    
    return isImage;
}

💻 Code Examples - Frontend

  • Method to Edit a meme.
// Patching the meme
response = await fetch(`/memes/${this.props.id}`,{
    method: "PATCH",
    headers: {"Content-Type": "application/json"},
    body: JSON.stringify({
        "url": this.state.url,
        "caption":  this.state.caption
    })
});

🆒 Features - Backend

  • All data stored in PostgreSQL database that can also be viewed and changed from the PostgreSQL shell (psql)
  • The Image URL is validated in the backend to avoid issues further.
  • Swagger UI runs on http://localhost:8080/swagger-ui/ in development and is extremely useful for testing and documenting the APIs.

🆒 Features - Frontend

📋 Status & To-Do List

  • Status: Working front and back ends. App works and stores Memes in PostgreSQL database. Deploy to Heroku working.
  • To-Do (After Evaluation):
    • Add Authentication to Ensure correct Edit and Delete permissions (Currently deletion is only possible with the use of master password)
    • Add feature to detect and delete/stop NSFW content, using an external API.