HackMD
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # 雲端架站 PPT ver. [Shizuku](https://www.facebook.com/shizuku.ichi)@CNA PPT: https://goo.gl/gC6hH8 --- ## About me * 喜歡將程式融入生活中,讓生活更優雅(? * 略懂 Python * 但今天用的是 Javascript --- ## 讓你聽聽 * Git 版本控管 * 雲端架站 * Heroku * 雲端部屬 * FB Chatbot 實作 --- ## [Git 版本控管](https://github.com/ShizukuIchi/PPT/blob/master/Git/Git.md) ---- ## 基本指令介紹 + clone/init + remote + add/commit + push/pull ---- ### 範例 1 ```shell // 從網路下載程式碼 $ git clone https://XXX.git // 修改檔案 a.txt 並確認 a.txt 的變更 $ git add a.txt // 儲存變更(本地端) $ git commit -m "bug fixed" // 將修改後的程式碼上傳 $ git push origin master ``` ---- ### 範例 2 ```shell // 寫了好多程式 $ git init // 所有檔案變更加入追蹤 $ git add . // 儲存變更(本地端) $ git commit -m "first commit" // 設定上傳的地址 $ git remote add origin https://XXX.git // 上傳至網路 $ git push origin master ``` --- ## 雲端架站 ---- ![淹水](https://media.giphy.com/media/l41YcLnzt7SNyxUha/giphy.gif) ---- ![窮](https://media.giphy.com/media/132pnhRx4EM7ni/giphy.gif) ---- ![意外](https://media.giphy.com/media/5Zesu5VPNGJlm/giphy.gif) --- ## 雲端選擇 ---- ### Iass 從頭來 AMZ、DigitalOcean 提供的就是 Iass 就像租一台主機,從基礎開始建置 -> 遠端連上主機操作 ---- ### Pass 包好好 等等介紹的 Heroku 就是 Pass 基礎環境設定好了,使用 API 做額外設定 -> 安裝專屬 Cli 操作 ---- ### 選擇 * 通常 Pass 會比 Iass 貴 * Iass 從頭打造,彈性更高 --- ## Heroku * 免費額度 * 可和 Github 連結 * 基本功能不需綁信用卡 * 自訂 subdomain ---- ## [Heroku Cli](https://cli-assets.heroku.com/heroku-cli/channels/stable/heroku-cli-windows-x64.tar.gz) 可以透過網站管理 Heroku 帳戶,不過有 Command line/shell 方便許多。 同時安裝 [Git](https://git-scm.com/) 以及設定環境變數。 --- ## Getting Started ---- [**下載 Git**](https://git-scm.com/download/) 檢查環境需求 ```shell $ git --version ``` ---- ## 擁有 Heroku ---- 1. [**註冊 Heroku**](https://signup.heroku.com/) (語言選 Nodejs, 需驗證 email) 2. [**建立 Heroku App**](https://dashboard.heroku.com/apps) 3. 取個喜歡的 App 名稱 ---- ## 下載範例程式碼 ---- > $ 部分皆在 Git cmd 框框內操作 抓檔案 ```shell $ git clone https://github.com/heroku/node-js-getting-started.git ``` 進入資料夾 ```shell $ cd node-js-getting-started ``` ---- 設定程式碼上傳的地方 ```shell $ git remote add heroku https://git.heroku.com/你的App名稱.git $ git remote -v ``` **※不准直接給我打"你的App名稱"進去** 打錯的話? ```shell $ git remote remove heroku ``` --- ## 上傳檔案囉 ---- 先登入heroku (只有這次在heroku cli) ```shell $ heroku login ``` 檔案上傳至 Heroku (回到 git.cmd) ```shell $ git push heroku master ``` 開啟網址 ```shell https://你的App名稱.herokuapp.com/ ``` ---- ## 下課! --- ## 基本設定 ---- 設定 Procfile 告訴 Heroku 主機如何執行 server ```= web: node index.js ``` 暫停使用 ```shell $ heroku ps:scale web=0 ``` --- ## 檢查狀況 ---- 查看 log ```shell $ heroku logs [--tail] ``` 查看 App 狀況 ```shell $ heroku ps ``` --- ## 小試身手 ---- 修改檔案 ```javascript= // 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行 ```javascript= // 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 }`)) ``` ---- 上傳試試 ```shell $ git commit -am 'hi' $ git push heroku master ``` 開啟網址 ```shell https://你的App名稱.herokuapp.com/hello ``` --- ## 敏感資訊? ---- 有些資訊直接寫在程式碼裡面不太OK 可在 Settings > Config Variables 設定 ![](https://i.imgur.com/IJjYuFA.png) Heroku 以 `process.env.name` 取得 value --- ## 實作 FB Chatbot! ---- 1. 下載 [zip檔案](https://github.com/ShizukuIchi/my-chatbot/archive/master.zip) 至剛剛的資料夾 2. 建立 Heroku App 並取名 ---- 3. 使用 git 上傳至heroku ```shell $ 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 ``` ---- 3. [建立FB應用程式](https://developers.facebook.com/apps/) * 成為 FB App 開發人員 * 新增應用程式 (Messenger) 4. 往下拉到權杖產生 * 建立粉絲專頁 (休閒娛樂) * 選擇剛創立的粉專 * 建立並複製產生的一大串英數字 ---- 5. webhooks -> 設定webhook ![](https://i.imgur.com/og5MYE2.png) ---- 6. 訂閱創立的粉絲專頁 7. 將權杖放入 Heroku Config ![](https://i.imgur.com/W8ln52D.png) ---- 8. [驗證權杖](https://www.hurl.it/) 右邊格子填入 https://graph.facebook.com/v2.6/me/subscribed_apps?access_token=權杖 ![](https://i.imgur.com/RkN7wtp.png) ---- 9. 開始測試吧!!!! ![](https://i.imgur.com/jwkx7Oa.png) --- ## Q_Q & A_A asdfghjkl

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully