MSBA-271 · Lesson 9 of 12 · 19 min
Deploying and managing code apps
▶ Video coming soon A video version of this lesson is on the way.
A working app on a developer's machine is not a service. Before Hamza's counter staff could rely on the athletics equipment loans app, it had to be published, shared, secured, monitored and moved through Lumenvale's environments like every other facilities app. Rupert joined this session because most of what follows happens in the admin center and the pipelines his governance team runs, and Delphine Okoro-Vance, the facilities business owner, joined to decide who should get access.
Publishing to an environment
The push command builds the app and publishes it to the environment the project is connected to. The first push creates the app; later pushes publish new versions. After a push the app appears in the Power Apps apps list beside canvas and model-driven apps, with its own link, and it can be opened by anyone it is shared with who has a suitable license.
npm run build
npx pa app pushFor anything beyond a developer environment, the app belongs in a solution. Code apps are solution-aware: Wiremu added the app to the Athletics Equipment solution alongside the Equipment Item and Equipment Loan tables, the cloud flow for overdue reminders and the environment variable for the loan period. The same pipelines that moved the facilities solution from Facilities Dev to Facilities Test and then to Lakeshore Ops, described in MSBA-270, now moved the code app. One limitation matters here: code apps do not support Power Platform Git integration, so the app's source lives in the facilities repository as an ordinary web project, and the solution carries the built app.
Sharing and running
Sharing a code app works like sharing a canvas app. The owner shares it with users or with Microsoft Entra security groups, and canvas app sharing limits apply. Lumenvale shared the loans app with one security group, Athletics Equipment Staff, whose membership Delphine approved and Rupert's team maintained, and gave the group's members the Athletics Equipment security role in Dataverse so that the data calls would succeed. Guests from other tenants can use code apps under B2B rules, which did not apply here.
For automated deployment, pipelines can deploy as a service principal, an application identity rather than a person. Lumenvale's pipelines already did, and the code app needed nothing new. Rupert noted that sharing is a separate step from deployment, so the pipeline's last stage confirmed that the app was shared with the right group in each environment rather than assuming it.
Content Security Policy
Code apps run in the browser and can load scripts and call addresses like any web page, so the platform protects them with a Content Security Policy (CSP), a browser feature that limits where a page may load code, styles, images and frames from and which addresses it may call. For code apps CSP is enforced by default, with a strict default policy. Among its defaults, scripts and other resources load only from the app's own origin, the app may be framed only by Power Apps, forms may not be submitted to other addresses, and the app may not open connections to other addresses at all.
| Directive | What it controls | Default for code apps |
|---|---|---|
| default-src | Where resources load from when no other directive applies | The app's own origin |
| connect-src | Addresses the app may call directly from script | None |
| frame-ancestors | Which pages may frame the app | The app itself and Power Apps |
| form-action | Where forms may be submitted | None |
| worker-src | Where web workers may load from | None |
Calls to data through the client library and generated services are designed to work under the default policy, which is why the loans app needed no CSP change for Dataverse, Office 365 Users or its flow. A change is needed when the app's own code calls an outside address directly, loads a font or image from another site, or uses a web worker. Wiremu's first draft loaded the athletics fonts from the communications office's web server, and the browser console showed them blocked. He bundled the fonts into the app instead, which was the better fix, since it removed an outside dependency.
When a change is needed, an administrator configures it per environment in the Power Platform admin center, under Settings, Product, Privacy + Security, Content security policy, on the app tab, or through environment settings in the platform API. Custom values are added to the default for a directive, or replace a default of none. The same page can set a reporting endpoint, an address that receives a report whenever the browser blocks something, which is useful before tightening a policy. CSP can also be turned off for code apps in an environment, but Rupert's rule was that it stays on everywhere except a developer's own environment.
Monitoring with Application Insights
Once real users depend on an app, the team needs to know when it is slow or failing before the users say so. Code apps can send telemetry to Azure Application Insights, the same service MSBA-270 used for canvas apps. The developer connects the app to an Application Insights resource and can log page views, custom events, exceptions and timing from the app's own code. Lumenvale's facilities Application Insights resource already received telemetry from the Field Tech app; the loans app joined it, with a property naming the app so that queries could tell them apart.
Wiremu logged three custom events: loan created, item returned and save failed, each with the time taken. These answered the questions Hamza and Rupert actually had: how many loans a day, how long a loan took to save at the counter, and whether failures clustered at certain times. The setup steps are in Microsoft's documentation for code apps and Application Insights, which Wiremu followed rather than guessing, because they had changed during the preview.
| Question | Where to look |
|---|---|
| Is the app failing for users? | Application Insights exceptions and the save-failed event |
| Is the app slow? | Application Insights timings and page views, and the browser's network tools |
| What did one session do? | Monitor in Power Apps, which shows a live log of an app session's activity |
| Is a resource blocked by CSP? | The browser console and the CSP reporting endpoint |
| How is the app used overall? | App health metrics in the Power Platform admin center |
Troubleshooting with Monitor and developer tools
When a user reports a problem, the first tools are the same as for any web app: the browser's developer tools, with the console, network and sources panels described in lesson 11. Power Apps Monitor adds a live log of the app session, including the data calls made through the platform, their timing and their results. A maker or developer can start Monitor and open the app, or invite a user to connect a session to Monitor so that their activity can be watched as it happens. Monitor showed Wiremu that one slow save was not the app at all, but the overdue reminder flow being started synchronously; he changed the app to start the flow without waiting for it.
Performance
A code app's performance is mostly ordinary web performance, so the usual rules apply. Keep the bundle small: the loans app loaded only the components needed for the counter screen at start and loaded the reports screen when it was opened. Call data less often: select only the columns needed, page large lists and cache reference data such as item categories for the session. Avoid waterfalls of calls where one waits for another when they could run together. And measure, with Application Insights timings and the browser's performance tools, rather than guessing.
| Practice | What it did for the loans app |
|---|---|
| Select only needed columns | Smaller responses for the item list |
| Load the item list once and filter locally | Instant search as staff type a tag number |
| Lazy-load rarely used screens | Faster first load on the counter tablet |
| Run independent calls together | Borrower details and loan history load at the same time |
| Start long flows without waiting | Saving a return no longer waits for the reminder flow |
Limits to know before choosing a code app
Code apps are generally available, but some platform features do not apply to them, and an architect should know the list before choosing one. At the time of writing Microsoft's overview lists, among others: no Power Platform Git integration, no running in Power Apps for Windows, no Power BI integration of the PowerBIIntegration kind, no use as SharePoint list forms, no Secure Implicit Connections, and the shared access signature IP restriction does not apply. Lumenvale's inventory of facilities apps recorded these beside the loans app so that a later team would not plan, for example, to embed it in a SharePoint form.
Governance, on the other hand, largely applies as for other apps. Data loss prevention policies are enforced when the app starts, Conditional Access applies to its users, administrators can quarantine it, tenant isolation applies, and app health metrics appear in the admin center. Rupert checked the facilities DLP policy and confirmed that the Office 365 Users connector was in the same business group as Dataverse, so the app would start.
Worked problem
Diagnosing a blocked call
After a release to Facilities Test, the loans app's new weather banner, which warns of outdoor events in bad weather, shows nothing. Other features work. The banner calls a public weather service directly from the app's code. What is the likely cause and the right fix?
Show solution
- Open the browser console. It shows that the request was refused because it violates the connect-src directive.
- Recognize that this is CSP working as designed: direct calls to outside addresses are blocked by default.
- Choose a fix. Either ask Rupert's team to add the weather service's address to connect-src for the environment, or call the service through a connector, which the platform governs with DLP.
- Prefer the connector, which keeps the call visible to governance and works without changing CSP in every environment.
Answer: The call was blocked by the default CSP. The team chose a custom connector for the weather service, so the call went through the platform and no CSP exception was needed.
The release checklist
Rupert turned the session into a checklist that the pipeline's approval step linked to, so that every release of a code app checked the same things. Most of it was automated; the rest took a few minutes by hand.
| Check | How |
|---|---|
| Build passes with tests and linting | GitHub Actions on every pull request |
| Environment variable values set for the target | Deployment settings in the pipeline |
| App shared with the right security group | Pipeline step that verifies sharing |
| CSP allows only what the app needs | Admin center review when the app's addresses change |
| Telemetry arriving in Application Insights | Check for the app's events after deployment |
| Accessibility review passed | Sign-off from accessibility services for new screens |
Connections need a word of their own. When a code app uses connectors, such as Office 365 Users, each user may be asked to allow the app to use their connection the first time they open it, as with canvas apps. Hamza's staff saw this prompt once, and Wiremu added a line about it to the short guide on the counter so that nobody was surprised.
Common mistakes
MistakeTurning CSP off to make a blocked call work.
InsteadRoute the call through a connector or add only the needed address to the policy.
MistakeAssuming deployment also shares the app.
InsteadShare with a security group in each environment and check it in the pipeline.
MistakePlanning to use Power Platform Git integration for a code app.
InsteadKeep the source in a normal Git repository; code apps do not support Git integration.
MistakeWaiting for user reports to find failures.
InsteadSend telemetry to Application Insights and watch it.
MistakeGuessing why the app is slow.
InsteadMeasure with Application Insights timings, Monitor and browser tools.
The loans app reached Facilities Test through the pipeline in its first full release. Hamza's staff tried it at the counter during practice sessions, and the Application Insights dashboard showed saves well under a second. Production would follow the accessibility review in lesson 10, because Ingrith had made that review a condition for every student-facing and staff-facing app the facilities program released.
Summary and key terms
- Push publishes a code app to the connected environment; for test and production, add it to a solution and deploy with pipelines.
- Share with users or security groups, give them the right Dataverse roles, and use a service principal for automated deployment.
- CSP is enforced by default and blocks direct calls to outside addresses; administrators can extend it per environment and set a reporting endpoint.
- Send telemetry to Application Insights, and use Monitor and browser developer tools to troubleshoot.
- Apply ordinary web performance practices and measure them.
- Know the limits, such as no Git integration and no SharePoint forms, before choosing a code app.
- Content Security Policy
- A browser feature that limits where a page may load resources from and which addresses it may call.
- connect-src
- The CSP directive controlling addresses a page may call from script; none by default for code apps.
- Reporting endpoint
- An address that receives reports when CSP blocks something.
- Service principal
- An application identity used by automated processes such as pipelines.
- Monitor
- A Power Apps tool showing a live log of an app session's activity.
- Application Insights
- An Azure service that collects telemetry such as events, timings and exceptions.
Practice problems
Work each problem on paper first, then reveal the answer to check.
Why did Dataverse calls work under the default CSP while the outside fonts did not?
Show answer
Data calls go through the client library, which the default policy allows; direct loads from other sites are blocked by default.
Name two ways to fix a call blocked by connect-src.
Show answer
Route the call through a connector, or have an administrator add the address to the policy for the environment.
What did Monitor reveal about the slow save?
Show answer
The app was waiting for the reminder flow to finish; starting it without waiting fixed the delay.
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.