loopback 代碼解析

loopback-bootjava

boot(app, __dirname);//server.jsgit

  • var instructions = compile(options);
    execute(app, instructions, callback); //(index.js)github

  • setHost(app, instructions);
    setPort(app, instructions);
    setApiRoot(app, instructions);
    applyAppConfig(app, instructions);json

    setupDataSources(app, instructions);
    setupModels(app, instructions);api

  • 初始化配置:環境、數據源、model (lib/executor.js)
  • 初始化路由? -- where angular-routes
  • async.series([
    function(done) {
    runBootScripts(app, instructions, done);
    },app

//讀取全部server/boot/目錄下面的, (配置對應的路由與處理能夠寫在這裏)async

  • 配置restapi 路由

loopback route 處理:oop

  • first go through middleware: proxy rate-limit oAuth https-redirect 作權限等檢查
  • 最終到達api end point (咱們的api controller處理)  , check out  loopback-gateway 

自帶 mobile  sdk:rest

  • //簡化了重複解析json結構的流程,直接上一個object
    ModelRepository productRepository = adapter.createRepository("product"); Model pen = productRepository.createModel( ImmutableMap.of("name", "Awesome Pen") );

項目結構:server

- common
|---- models // both server and client use
- client
|---- models-config.json //view in Angular or hybrid mobile app
- server
|---- models-config.json

example https://github.com/strongloop/loopback-example-full-stack

相關文章
相關標籤/搜索