Serverless CN
      • 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
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners 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 No publishing access yet

      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.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      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 New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy 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
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners 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 No publishing access yet

    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.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 分析 Chinese dev mode 和 Global dev mode ###### tags: `cli` Dev mode 分为两部分: ### CLI 前端部分 Global 和 Chinese 这边在cli的这部分的逻辑基本相同: 1. 监听项目文件变化 2. 变化之后出发 `deploy` 3. 建立 **websocket** 连接,得到主动推送的功能 第三步建立连接这里有不同: 1. Chinese: 直接通过腾讯提供的[utils-china包中的方法建立ws连接](https://github.com/serverless/components/blob/65fccf543153407fbc2b855bfa777433408e0430/src/cli/commands-cn/dev.js#L114), [sdk中的封装](https://github.com/serverlessinc/platform-cn/blob/2aa2292c89550dd801a4a411b61f862153c7d9a1/sdk/src/utils.js#L568) 2. Global: [通过SDK的connect方法建立的ws连接](https://github.com/serverless/components/blob/65fccf543153407fbc2b855bfa777433408e0430/src/cli/commands/dev.js#L221), [sdk的connect文档](https://github.com/serverlessinc/platform/tree/master/sdk#serverlesssdkconnectoptions--null) ### Dev 后端部分 1. Chinese: 通过腾讯[utils-china]中的方法,直接调用腾讯的api建立ws连接,进行服务端的dev 日志推送: https://github.com/serverlessinc/platform-cn/blob/2aa2292c89550dd801a4a411b61f862153c7d9a1/sdk/src/utils.js#L568 2. Global:cli调用sdk中的`connect` 方法,建立ws连接:https://github.com/serverlessinc/platform/tree/master/sdk#serverlesssdkconnectoptions--null, 1. connect方法通过参数构建 WS URL, 建立Events的websocket 连接: https://github.com/serverlessinc/platform/blob/593e41f98dc013053e414b2b699c81e12bb03c7c/sdk/src/Connection.js#L23 2. 连接到 Events 服务,events 服务提供ws主动推送:https://github.com/serverlessinc/platform/blob/593e41f98dc013053e414b2b699c81e12bb03c7c/sp-events/code/src/handler.js#L212 ### 这是我询问 Eslam 关于 Global dev mode的架构设计,他给的答复: > Hey Meng, unfortunately we don’t have such doc. Not sure how much details you need, but to sum it up: > 1. on dev mode, we connect via websockets to our platfrom event bus backend by providing certain context information (orgName, serviceName..etc) > 2. during first deployment, we inject our own SDK into the user’s lambda as a middleware that runs on every lambda invocation > 3. on every lambda invocation during dev mode, the SDK has an async timer than runs every 100ms or something that collections all the logs the user logged and patch-request them to our platform event bus backend along with context information (orgName, serviceName…etc)p > 4. our platform event bus backend receives the events and pushes them over the websocket connect established with the CLI according to the context information, and this is how the CLI receives the logs > 5. the watching feature is pretty straightforward. We just watch the directory and redeploy on changes 我根据global的代码对于上面Eslam说的这几步梳理了一下代码所在: 1. https://github.com/serverless/components/blob/65fccf543153407fbc2b855bfa777433408e0430/src/cli/commands/dev.js#L221: connect方法调用,建立cli和event bus的ws连接 2. [deploy的时候添加dev: true Option](https://github.com/serverless/components/blob/6e485ae27f9b38c8694b34c0e7dc95d962cb7f4c/src/cli/commands/dev.js#L278), 最终这个字段会注入到[addSDK](https://github.com/serverlessinc/platform/blob/593e41f98dc013053e414b2b699c81e12bb03c7c/sp-registry/layer/src/handler.js#L167)这个方法中,完成sdk的注入 3. Lambda 函数执行的时候,sdk会向我们的event bus 发送请求: https://github.com/serverlessinc/platform/blob/593e41f98dc013053e414b2b699c81e12bb03c7c/sp-events/code/src/handler.js#L212 4. Evnet bus 收到请求,会根据context information筛选信息,然后通过第一步建立的ws连接。推送到cli: https://github.com/serverlessinc/platform/blob/593e41f98dc013053e414b2b699c81e12bb03c7c/sp-events/code/src/handler.js#L99 5. 这一步是监听用户文件然后触发重新部署,没有特殊的地方

    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
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    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