Skip to content

gregtandiono/OrgCommNodeK8

Repository files navigation

OrgCommNodeK8

Despite having a k8 in the name, this project does not actually utilize K8 orchestration.

Pre-requisites:

Run the project container via Docker Compose

In the project root directory, run:

# run in `detached` mode (recommended):
docker-compose up -d

# Or run attached, you will see both container logs: mongodb init log and running server log
docker-compose up

# to stop containers generated by docker-compose, run:
docker-compose down

Docker compose will pull & build both the project and the mongodb image from docker hub. After compose has successfully built the images, go to http://localhost:1337 to verify that the container is running.

Endpoints and Default Data

By default, the database has been pre-populated with a set of organizations, comments and members.

Available organizations to query from:

  • fsociety
  • ecorp

Available Endpoints

[GET] /orgs/{orgName}/comments

curl -i /orgs/fsociety/comments

HTTP/1.1 200 OK
BODY:
[
  {
    "deleted": false,
    "_id": "5d61050a854b8e001cb96896",
    "comment": "i miss qwerty...",
    "org": "fsociety",
    "createdAt": "2019-08-24T09:36:10.846Z",
    "updatedAt": "2019-08-24T09:36:10.846Z",
    "__v": 0
  },
  {
    "deleted": false,
    "_id": "5d61050a854b8e001cb96897",
    "comment": "where is darlene?",
    "org": "fsociety",
    "createdAt": "2019-08-24T09:36:10.846Z",
    "updatedAt": "2019-08-24T09:36:10.846Z",
    "__v": 0
  }
]

[POST] /orgs/{orgName}/comments

curl -d '{"comment": "Bonsoir!"}' \
-H "Content-Type: application/json" \
-X POST http://localhost:1337/orgs/ecorp/comments

HTTP/1.1 200 OK

[DELETE] /orgs/{orgName}/comments

curl -i -X DELETE http://localhost:1337/orgs/fsociety/comments

HTTP/1.1 200 OK

[GET] /orgs/{orgName}/members

curl -i http://localhost:1337/orgs/fsociety/members

HTTP/1.1 200 OK
BODY:
[
  {
    "avatar": "https://i.pravatar.cc/300",
    "followers": 33,
    "following": 11,
    "_id": "5d61050a854b8e001cb96890",
    "email": "[email protected]",
    "org": "fsociety",
    "createdAt": "2019-08-24T09:36:10.811Z",
    "updatedAt": "2019-08-24T09:36:10.811Z",
    "__v": 0
  },
  {
    "avatar": "https://i.pravatar.cc/300",
    "followers": 18,
    "following": 7,
    "_id": "5d61050a854b8e001cb96891",
    "email": "[email protected]",
    "org": "fsociety",
    "createdAt": "2019-08-24T09:36:10.811Z",
    "updatedAt": "2019-08-24T09:36:10.811Z",
    "__v": 0
  },
  {
    "avatar": "https://i.pravatar.cc/300",
    "followers": 7,
    "following": 21,
    "_id": "5d61050a854b8e001cb9688f",
    "email": "[email protected]",
    "org": "fsociety",
    "createdAt": "2019-08-24T09:36:10.810Z",
    "updatedAt": "2019-08-24T09:36:10.810Z",
    "__v": 0
  }
]

Build for Local Development

Install dependencies:

yarn

Run the server:

yarn start

Running yarn start will run a seed script via node seed.js to insert default set of collections and documents to your local mongodb db.

Run unit and integration tests:

# run without nyc coverage
yarn test

# run with nyc coverage report
yarn test:coverage

If you're going to develop on your local machine, it is recommended that you use tools like nodemon for watch or reload. However, it is recommended that you run the seed script first to get some data in your mongodb database.

# Run seed script (recommended)
node ./seed.js

# Run server
nodemon index.js

Build docker image

Before you do, you need to create a production config /config/production.json:

{
  "host": "localhost",
  "port": 1337,
  "db": {
    "connString": "mongodb://mongo:27017/orgcommnode"
  }
}

Then run:

docker build -t orgcommnode-rest .

You can replace the orgcommnode-rest tag with any name you want.

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published