refactor: app embedding as middleware