Skip to content

Commit

Permalink
first one
Browse files Browse the repository at this point in the history
  • Loading branch information
osamabari committed Oct 4, 2019
0 parents commit 901eb5b
Show file tree
Hide file tree
Showing 42 changed files with 9,213 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
13 changes: 13 additions & 0 deletions .dockerignore
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
13 changes: 13 additions & 0 deletions .editorconfig
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
6 changes: 6 additions & 0 deletions .env.example
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
19 changes: 19 additions & 0 deletions .eslintrc
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"
]
}
6 changes: 6 additions & 0 deletions .gitattributes
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
46 changes: 46 additions & 0 deletions .gitignore
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
30 changes: 30 additions & 0 deletions .travis.yml
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
14 changes: 14 additions & 0 deletions Dockerfile
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"]
125 changes: 125 additions & 0 deletions README.md
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
```
5 changes: 5 additions & 0 deletions apidoc.json
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"
}
12 changes: 12 additions & 0 deletions deploy.sh
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
6 changes: 6 additions & 0 deletions docker-compose.dev.yml
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
6 changes: 6 additions & 0 deletions docker-compose.prod.yml
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
6 changes: 6 additions & 0 deletions docker-compose.test.yml
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
18 changes: 18 additions & 0 deletions docker-compose.yml
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"

Loading

0 comments on commit 901eb5b

Please sign in to comment.