Shizuku@CNA
PPT: https://goo.gl/gC6hH8
// 從網路下載程式碼
$ git clone https://XXX.git
// 修改檔案 a.txt 並確認 a.txt 的變更
$ git add a.txt
// 儲存變更(本地端)
$ git commit -m "bug fixed"
// 將修改後的程式碼上傳
$ git push origin master
// 寫了好多程式
$ git init
// 所有檔案變更加入追蹤
$ git add .
// 儲存變更(本地端)
$ git commit -m "first commit"
// 設定上傳的地址
$ git remote add origin https://XXX.git
// 上傳至網路
$ git push origin master
AMZ、DigitalOcean 提供的就是 Iass
就像租一台主機,從基礎開始建置
-> 遠端連上主機操作
等等介紹的 Heroku 就是 Pass
基礎環境設定好了,使用 API 做額外設定
-> 安裝專屬 Cli 操作
可以透過網站管理 Heroku 帳戶,不過有 Command line/shell 方便許多。
同時安裝 Git 以及設定環境變數。
下載 Git
檢查環境需求
$ git --version
$ 部分皆在 Git cmd 框框內操作
抓檔案
$ git clone https://github.com/heroku/node-js-getting-started.git
進入資料夾
$ cd node-js-getting-started
設定程式碼上傳的地方
$ git remote add heroku https://git.heroku.com/你的App名稱.git
$ git remote -v
※不准直接給我打"你的App名稱"進去
打錯的話?
$ git remote remove heroku
先登入heroku (只有這次在heroku cli)
$ heroku login
檔案上傳至 Heroku (回到 git.cmd)
$ git push heroku master
開啟網址
https://你的App名稱.herokuapp.com/
設定 Procfile
告訴 Heroku 主機如何執行 server
web: node index.js
暫停使用
$ heroku ps:scale web=0
查看 log
$ heroku logs [--tail]
查看 App 狀況
$ heroku ps
修改檔案
// index.js express() .use(express.static(path.join(__dirname, 'public'))) .set('views', path.join(__dirname, 'views')) .set('view engine', 'ejs') .get('/', (req, res) => res.render('pages/index')) .listen(PORT, () => console.log(`Listening on ${ PORT }`))
貼心提醒: 第8行
// index.js express() .use(express.static(path.join(__dirname, 'public'))) .set('views', path.join(__dirname, 'views')) .set('view engine', 'ejs') .get('/', (req, res) => res.render('pages/index')) .get('/hello', (req, res) => res.send('olleh')) .listen(PORT, () => console.log(`Listening on ${ PORT }`))
上傳試試
$ git commit -am 'hi'
$ git push heroku master
開啟網址
https://你的App名稱.herokuapp.com/hello
有些資訊直接寫在程式碼裡面不太OK
可在 Settings > Config Variables 設定
Heroku 以 process.env.name
取得 value
$ cd my-chatbot-master
$ git init
$ git add .
$ git commit -m "first commit"
$ git remote add heroku https://git.heroku.com/你的App名稱.git
$ git push heroku master
往下拉到權杖產生
訂閱創立的粉絲專頁
將權杖放入 Heroku Config
asdfghjkl