Giter Site home page Giter Site logo

martinsonuoha / secret-server Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 2.0 1.49 MB

A Node.js + Vue secret server project

Shell 2.05% JavaScript 65.78% HTML 3.01% Vue 22.49% Dockerfile 6.67%
secret-server vue vuejs javascript nodejs backend docker docker-container frontend-application

secret-server's Introduction

Secret Server

image

A secret server to store and share secrets using a random generated URL.

How it Works

A Secret is provided to the server by the visitor, as well as the maximum number of times it can be viewed and when it should be deleted:

"I ate all the cookies in the fridge"

"view this secret": 10 times

"delete this secret": On the 30th, January, 2021

The Frontend application sends this data to the secret server in this format:

{
  "secret": "I ate all the cookies in the fridge",
  "expireAfterViews": 10,
  "expireAfter": "2021-01-30T03:36:16.543Z"
}

The server receives this data and encrypts the user's secret using AES (Advanced Encryption Standard) Encryption in CTR mode, using a server secret key.

crypto.createCipheriv(ALGO, SECRET_KEY, IV);

The secret server doesn't save the secret in plain text:

{
  "remainingViews": 5,
  "createdAt": "2021-01-21T10:19:14.918Z",
  "expiresAt": "2021-01-21T03:36:16.543Z",
  "_id": "600955250de4884054d0c029",
  "hash": "32f8a1ca19fd378a60a7c6cfc449557f",
  "secret": {
    "iv": "e0a4492c1399ea79e5da0e848a60ab4e",
    "encryptedContent": "f647465a31184cfd3bbc7affb96d80355363a26f6e743b88"
  },
  "__v": 0
}

When the secret is retrived the server deciphers the stored secret to plain text and reduces the views count:

"I ate all the cookies in the fridge"

API Docs

  1. POST /api/secret

    • Payload: JSON
    {
      "secret": "I ate all the cookies in the fridge",
      "expireAfterViews": 5,
      "expireAfter": "2021-01-21T03:36:16.543Z"
    }
    • Response:
    {
      "hash": "d2634e70424af635926eb196f11c03f7",
      "secretText": "This is a new secretokay",
      "createdAt": "2021-01-21T10:39:16.564Z",
      "expiresAt": "2021-01-21T03:36:16.543Z",
      "remainingViews": 5
    }
  2. GET /api/secret/d2634e70424af635926eb196f11c03f7

    • Response:
      {
        "hash": "d2634e70424af635926eb196f11c03f7",
        "secretText": "This is a new secretokay",
        "createdAt": "2021-01-21T10:39:16.564Z",
        "expiresAt": "2021-01-21T03:36:16.543Z",
        "remainingViews": 5
      }

Project Structure

|
`-- ๐Ÿ“‚ client
`-- ๐Ÿ“‚ server
`-- README.md
`-- package.json
  • ๐Ÿ“‚ Client
this folder contians the source code for the frontend application written in Vue.js
  • ๐Ÿ“‚ Server
this folder contains the source code for the backend application written in Node.js

Running the Application

Option 1: With Docker

  • Requirements
    • docker installation

NOTE: The .env file for testing has been pushed to the repo for convenience sake only.

To run the application locally, First, Clone the repository:

git clone https://github.com/MartinsOnuoha/secret-server.git

Navigate into the project root

cd secret-server

Next build the images

docker-compose build

start the containers

docker-compose up

Great! Now the frontend application should be accessible on http://localhost:8080


Option 2: Without Docker

  • Requirements
    • Node.js & NPM setup
    • MongoDB Installation

clone the repository

git clone https://github.com/MartinsOnuoha/secret-server.git

change directory into the project folder

cd secret-server

Update the .env file with these values:

PORT=4000
HOST='0.0.0.0'
TEST_PORT=8080
DEV_DB="mongodb://localhost:27017/secret-server"
TEST_DB="mongodb://localhost/secret-server-test"
SECRET_KEY="5eb4b1358299539c686530e37e1173e2"
ALGO="aes-256-ctr"

Install Dependencies and Start the backend Server

cd server && yarn && node app

Start the frontend Application

cd client && yarn && yarn serve

You should now be able to navigate to the application from your browser on http://localhost:8080


Tests

Option1: With Docker

The Frontend and Backend Tests are executed when the docker containers are started. And you can see them in the docker log.

image

image

If you're unable to see the logs, you can run docker-compose log to view it.

docker-compose log --tail="30"

Option2: Without Docker

However for running tests outside of the docker container. You need to run both tests individually.

  • Frontend
cd client && yarn test:unit
  • Backend
cd server && yarn test:server

secret-server's People

Contributors

martinsonuoha avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.