Academic use
Use your preferred text editor to create the .env
file:
HTTP_HOST=twitter-api
HTTP_PORT=8080
JWT_SECRET_KEY=jwt_secret_key
JWT_HEADER_KEY=jwt_header_key
DB_CONNECTION_STRING=mongodb://mongodb:27017/details
Note that you may use other hostname and/or port; however, bear in mind that you will need to edit the Dockerfile and the docker commands accordingly. You are strongly encouraged to use other values for the jsonwebtoken secret and header keys, for the ones given here are just examples.
Create a network with Docker so that DNS lookup works on App startup:
docker network create webnetwork
Pull the official image maintained by the Docker community from Docker Hub via (if you have not done so before):
docker pull mongo
Run an instance of the database
docker run --name mongodb --network webnetwork mongo
Note that the name mongodb is the same as the database hostname in the .env file. Feel free to use any other name you deem appropriate for the database.
Use your preferred text editor to create the Dockerfile for building the App Docker Image:
FROM node:16
WORKDIR /usr/src/app
RUN git clone https://github.com/misael-diaz/twitter-api.git /usr/src/app
RUN yarn install
RUN yarn add dotenv
RUN yarn add express
RUN yarn add mongoose
RUN yarn add jsonwebtoken
RUN yarn add bcrypt
RUN yarn add cors
EXPOSE 8080
CMD yarn start
Build the image:
docker image build -t im-twitter-api .
Deploy the Docker Container of the App on the foreground (useful for testing):
docker container run -it -p 8080:8080 --name twitter-api --network webnetwork --env-file .env im-twitter-api
alternatively, you may execute the App on the background by detaching:
docker container run -it -p 8080:8080 -d --name twitter-api --network webnetwork --env-file .env im-twitter-api
Note that the command requests docker to connect the App to the network webnetwork
,
that the name of the App twitter-api
is the same as the HTTP_HOST
in .env
,
and that the published port 8080
is the same as the HTTP_PORT
in .env
and the
exposed port in the Dockerfile.
To stop the App use:
docker container stop twitter-api
Methods | ||||
URL | GET | POST | PUT | DELETE |
/ | Displays "App works!" | Error | Error | Error |
/api/users/login | Error |
Authenticate User
|
Error | Error |
/api/users/signup | Error |
Create User
|
Error | Error |
/api/users/list |
|
Error | Error | Error |