Implement app.installMiddleware

The implementation is mostly a copy of
    loopback-workspace/templates/app.js