-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 901eb5b
Showing
42 changed files
with
9,213 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
node_modules/ | ||
.git/ | ||
.vscode/ | ||
coverage/ | ||
|
||
.dockerignore | ||
Dockerfile | ||
|
||
.gitignore | ||
.env | ||
.eslintrc | ||
.editorconfig | ||
.gitlab-ci.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
# trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
NODE_ENV=development | ||
PORT=3000 | ||
JWT_SECRET=samplesecret | ||
JWT_EXPIRATION_MINUTES=15 | ||
MONGO_URI=mongodb://localhost:27017/rest_api | ||
MONGO_URI_TESTS=mongodb://localhost:27017/rest_api_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"rules": { | ||
"no-console": 0, | ||
"no-underscore-dangle": 0, | ||
"no-unused-vars": ["error", { "argsIgnorePattern": "next" }], | ||
"no-use-before-define": ["error", { "variables": false }], | ||
"no-multi-str": 0 | ||
}, | ||
"env": { | ||
"node": true, | ||
"mocha": true | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 8 | ||
}, | ||
"extends": [ | ||
"airbnb-base" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Convert text file line endings to lf | ||
* text=auto | ||
*.js text | ||
# Denote all files that are truly binary and should not be modified. | ||
*.mp4 binary | ||
*.jpg binary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Use yarn.lock instead | ||
package-lock.json | ||
|
||
# Environment variables | ||
.env | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Documentation | ||
docs | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules | ||
jspm_packages | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional REPL history | ||
.node_repl_history |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
language: node_js | ||
|
||
cache: | ||
directories: | ||
- ~/.npm | ||
|
||
node_js: | ||
- '10' | ||
|
||
services: | ||
- mongodb | ||
|
||
git: | ||
depth: 3 | ||
|
||
branches: | ||
only: | ||
- master | ||
|
||
env: | ||
global: | ||
- NODE_ENV=test | ||
- PORT=3000 | ||
- JWT_SECRET=093nkasd0i12390123123 | ||
- JWT_EXPIRATION_MINUTES=15 | ||
- MONGO_URI=mongodb://localhost/rest_api | ||
- MONGO_URI_TESTS=mongodb://localhost/rest_api_test | ||
|
||
script: yarn validate | ||
after_success: yarn coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM node:10 | ||
|
||
EXPOSE 4000 | ||
|
||
ARG NODE_ENV | ||
ENV NODE_ENV $NODE_ENV | ||
|
||
RUN mkdir /app | ||
WORKDIR /app | ||
ADD package.json yarn.lock /app/ | ||
RUN yarn --pure-lockfile | ||
ADD . /app | ||
|
||
CMD ["yarn", "docker:start"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
# Phonebook Rest API | ||
|
||
|
||
Rest api for phonebook | ||
|
||
|
||
## Requirements | ||
|
||
- [Node v10>=](https://nodejs.org/en/download/current/) or [Docker](https://www.docker.com/) | ||
- [Yarn](https://yarnpkg.com/en/docs/install) | ||
|
||
## Getting Started | ||
|
||
#### Clone the repo and make it yours: | ||
|
||
```bash | ||
git clone --depth 1 https://github.com/osamabari/rest_api | ||
cd rest_api | ||
``` | ||
|
||
#### Install dependencies: | ||
|
||
```bash | ||
yarn | ||
``` | ||
|
||
#### Set environment variables: | ||
|
||
```bash | ||
cp .env.example .env | ||
``` | ||
|
||
## Running Locally | ||
|
||
```bash | ||
yarn dev | ||
``` | ||
and open http://localhost:3000/v1/status to check api is running or not | ||
|
||
## Running Documenation | ||
|
||
Step 1: | ||
|
||
```bash | ||
yarn docs | ||
``` | ||
|
||
Step2: | ||
```bash | ||
yarn dev | ||
``` | ||
Step3: | ||
|
||
open http://localhost:3000/v1/docs in web browser | ||
|
||
|
||
## Running in Production | ||
|
||
```bash | ||
yarn start | ||
``` | ||
|
||
## Lint | ||
|
||
```bash | ||
# lint code with ESLint | ||
yarn lint | ||
|
||
# try to fix ESLint errors | ||
yarn lint:fix | ||
``` | ||
|
||
## Test | ||
|
||
```bash | ||
# run all tests with Mocha | ||
yarn test | ||
``` | ||
|
||
## Logs | ||
|
||
```bash | ||
# show logs in production | ||
pm2 logs | ||
``` | ||
|
||
## Documentation | ||
|
||
```bash | ||
# generate and open api documentation | ||
yarn docs | ||
``` | ||
|
||
## Docker | ||
|
||
```bash | ||
# run container locally | ||
yarn docker:dev | ||
|
||
# run container in production | ||
yarn docker:prod | ||
|
||
# run tests | ||
yarn docker:test | ||
``` | ||
|
||
## Deploy | ||
|
||
Set your server ip: | ||
|
||
```bash | ||
DEPLOY_SERVER=127.0.0.1 | ||
``` | ||
|
||
Replace my Docker username with yours: | ||
|
||
```bash | ||
nano deploy.sh | ||
``` | ||
|
||
Run deploy script: | ||
|
||
```bash | ||
yarn deploy | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"title": "Phonebook Rest API", | ||
"url": "http://localhost:3000/", | ||
"description": "Documentation for PhoneBook Rest API" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
docker build -t osamabari/rest_api . | ||
docker push osamabari/rest_api | ||
|
||
ssh deploy@$DEPLOY_SERVER << EOF | ||
docker pull osamabari/rest_api | ||
docker stop rest-api || true | ||
docker rm rest-api || true | ||
docker rmi osamabari/rest_api:current || true | ||
docker tag osamabari/rest_api:latest osamabari/rest_api:current | ||
docker run -d --restart always --name rest-api -p 3000:3000 osamabari/rest_api:current | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: "2" | ||
services: | ||
rest-api: | ||
command: yarn dev -- -L | ||
environment: | ||
- NODE_ENV=development |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: "2" | ||
services: | ||
rest-api: | ||
command: yarn start | ||
environment: | ||
- NODE_ENV=production |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: "2" | ||
services: | ||
rest-api: | ||
command: yarn test | ||
environment: | ||
- NODE_ENV=test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
version: "2" | ||
services: | ||
rest-api: | ||
build: . | ||
environment: | ||
- MONGO_URI=mongodb://127.0.0.1:27018/rest_api | ||
volumes: | ||
- .:/app | ||
ports: | ||
- "4000:3000" | ||
depends_on: | ||
- mongodb | ||
|
||
mongodb: | ||
image: mongo | ||
ports: | ||
- "27018:27017" | ||
|
Oops, something went wrong.