loopback 代码解析
loopback-boot
boot(app, __dirname);//server.js
-
var instructions = compile(options);
execute(app, instructions, callback); //(index.js) -
setHost(app, instructions);
setPort(app, instructions);
setApiRoot(app, instructions);
applyAppConfig(app, instructions);setupDataSources(app, instructions);
setupModels(app, instructions); - 初始化配置:环境、数据源、model (lib/executor.js)
- 初始化路由? -- where angular-routes
-
async.series([
function(done) {
runBootScripts(app, instructions, done);
},
//读取所有server/boot/目录下面的, (配置对应的路由与处理可以写在这里)
- 配置restapi 路由
loopback route 处理:
- first go through middleware: proxy rate-limit oAuth https-redirect 做权限等检查
- 最终到达api end point (我们的api controller处理) , check out loopback-gateway
自带 mobile sdk:
-
//简化了重复解析json结构的流程,直接上一个object
ModelRepository productRepository = adapter.createRepository("product"); Model pen = productRepository.createModel( ImmutableMap.of("name", "Awesome Pen") );
项目结构:
- 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