![LGTM](https://camo.githubusercontent.com/ec612f40888a2b5f8287b42b2955120716ef00001bd42052f43e0b08c99eb671/68747470733a2f2f692e6c67746d2e66756e2f326f7a6f2e706e67)
$ npm install json-server
$ npm install json-server --prefix . // 폴더 내 설정
- Create a db.json file($ vi db.json)
cat db.json
{
"posts": [
{ "id": "1", "title": "a title", "views": 100 },
{ "id": "2", "title": "another title", "views": 200 }
],
"comments": [
{ "id": "1", "text": "a comment about post 1", "postId": "1" },
{ "id": "2", "text": "another comment about post 1", "postId": "1" }
],
"profile": {
"name": "typicode"
},
"kms": [
{ "id": "1", "name": "kim"},
{ "id": "2", "name": "hong"}
]
}
$ npx json-server db.json
JSON Server started on PORT :3000
Press CTRL-C to stop
Watching db.json...
( ˶ˆ ᗜ ˆ˵ )
Index:
http://localhost:3000/
Static files:
Serving ./public directory if it exists
Endpoints:
http://localhost:3000/posts
http://localhost:3000/comments
http://localhost:3000/profile
- branch 및 pr 생성 0.1.0/fly
- Dockerfile 생성($ vi Dockerfile)
$ cat Dockerfile
FROM node:20.11
WORKDIR /app
RUN npm install -g npm
RUN npm install -g json-server
COPY ./db.json /app
CMD ["json-server", "-p", "80", "-w", "/app/db.json"]
- https://fly.io/ 가입 - (주의! hobby plan 가입)
- 무료 플랜 : https://fly.io/docs/about/pricing/#free-allowances
- install cmd - https://fly.io/docs/hands-on/install-flyctl/
sudo curl -L https://fly.io/install.sh | sh
- vi ~/.zshrc 밑에 내용 추가
# fly
export FLYCTL_INSTALL="~/.fly"export PATH="$FLYCTL_INSTALL/bin:$PATH"
- 확인
$ tail -n 3 ~/.zshrc
# fly
export FLYCTL_INSTALL="~/.fly"
export PATH="$FLYCTL_INSTALL/bin:$PATH"
$ source ~/.zshrc
$ flyctl auth login
- Setting(fly.toml 수정)
$ cat fly.toml
# fly.toml app configuration file generated for joo-json-server on 2024-02-04T12:53:39+09:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#
app = 'joo-json-server'
primary_region = 'nrt'
[build]
[http_service]
internal_port = 80
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 3
processes = ['app']
[[vm]]
cpu_kind = 'shared'
cpus = 1
memory_mb = 256
- Launch
$ flyctl launch
⚠️ Do you want to tweak these settings before proceeding? Yes
? Create .dockerignore from 1 .gitignore files? No
![image](https://private-user-images.githubusercontent.com/91647614/302105019-04d79465-958e-419a-a283-c1ecf74dc803.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjYwMTg0MTEsIm5iZiI6MTcyNjAxODExMSwicGF0aCI6Ii85MTY0NzYxNC8zMDIxMDUwMTktMDRkNzk0NjUtOTU4ZS00MTlhLWEyODMtYzFlY2Y3NGRjODAzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTExVDAxMjgzMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTA4ZDY3MjNhMzVkOTNmZDQwYTc1ZjAzMzU3ZWI1MjlhZGMyNGM0NzI5NjJkNDg4YjNlZjM0OGRjN2ViZDZjYmMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.t3t_2RgGGXuTAisbizeid10D4o0EqbYCeLY9S6z-u6U)
- Setting(fly.toml 수정)
$ cat fly.toml
# fly.toml app configuration file generated for joo-json-server on 2024-02-04T12:53:39+09:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#
app = 'joo-json-server'
primary_region = 'nrt'
[build]
[http_service]
internal_port = 80
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 3
processes = ['app']
[[vm]]
cpu_kind = 'shared'
cpus = 1
memory_mb = 256
- Deploy
![image](https://private-user-images.githubusercontent.com/91647614/302105984-794e04ee-b04b-40f7-b54f-5ee8e472aeb0.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjYwMTg0MTEsIm5iZiI6MTcyNjAxODExMSwicGF0aCI6Ii85MTY0NzYxNC8zMDIxMDU5ODQtNzk0ZTA0ZWUtYjA0Yi00MGY3LWI1NGYtNWVlOGU0NzJhZWIwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTExVDAxMjgzMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTE1NzI3ZjEyNjFlYjg2MmU5OTc4ODQ1ZDE1MGI4NWU4OGI3YjY1NmJhNTNmMjUzNGY5ZDE1MGI2YTcxN2JmYTEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.1ZMLQ813lpXS6tQjuwWbtzzmbb35Lr5_hK93aLxWVUM)