Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(azure): support custom configuration #1344

Merged
merged 17 commits into from
Aug 20, 2023

Conversation

NicholasDawson
Copy link
Contributor

πŸ”— Linked issue

#1087

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

I, along with many others deploying a Nitro server to Azure Static Web Apps, need to customize the staticwebapp.config.json file beyond what Nitro generates. Currently, Nitro overwrites the entire file on every compilation. It would be better if Nitro extended an existing configuration if present not overwrite the whole file.

I added thorough documentation to explain how the system will now load and utilize the configuration. Please reference that to learn a little more about my implementation.

Implementation Notes

I put a lot of thought into this implementation as there wasn't necessarily a right or wrong way to handle this. I didn't originally want to have a separate file custom.staticwebapp.config.json, but the reason I had to add it was that if Nitro and the user are writing to the same file there is no way to keep track of what needs to take priority or be overwritten. Especially for routes, if Nitro generated the config for pre-rendered routes, but then the user deletes that pre-rendered route, it would be expected that the config removes that next time it compiles. If I tried to merge changes into the staticwebapp.config.json then Nitro would essentially lose the ability to remove lines from the configuration, only add them.

Therefore it was necessary to introduce the convention of having the user add their own configuration to a file I called custom.staticwebapp.config.json to provide a clear distinction between what the user wants to add and what the final generated result (staticwebapp.config.json) is.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@nuxt-studio
Copy link
Contributor

nuxt-studio bot commented Jun 25, 2023

βœ… Live Preview ready!

Name Edit Preview Latest Commit
nitro Edit on Studio β†—οΈŽ View Live Preview 1bf18a7

@codecov
Copy link

codecov bot commented Jun 25, 2023

Codecov Report

Merging #1344 (1bf18a7) into main (6cfdf01) will increase coverage by 1.40%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1344      +/-   ##
==========================================
+ Coverage   76.39%   77.80%   +1.40%     
==========================================
  Files          76       76              
  Lines        7790     7816      +26     
  Branches      784      797      +13     
==========================================
+ Hits         5951     6081     +130     
+ Misses       1837     1732     -105     
- Partials        2        3       +1     
Files Changed Coverage Ξ”
src/presets/azure.ts 90.28% <100.00%> (+76.19%) ⬆️

... and 2 files with indirect coverage changes

@Hebilicious Hebilicious self-requested a review June 30, 2023 19:15
@Hebilicious Hebilicious self-assigned this Jun 30, 2023
@Hebilicious Hebilicious added enhancement New feature or request preset:azure labels Jun 30, 2023 — with Volta.net
@NicholasDawson
Copy link
Contributor Author

NicholasDawson commented Jul 17, 2023

@Hebilicious
Can I please have an update on this PR? It has been 3 weeks, I tried really hard to add sufficient testing and documentation to make this PR easy to review and accept. I know you all must be very busy and I really appreciate your work, I would just appreciate an update on this PR.

@Hebilicious
Copy link
Contributor

Hebilicious commented Jul 17, 2023

@Hebilicious Can I please have an update on this PR? It has been 3 weeks, I tried really hard to add sufficient testing and documentation to make this PR easy to review and accept. I know you all must be very busy and I really appreciate your work, I would just appreciate an update on this PR.

Hi @NicholasDawson , thank you for your hard work on this PR, and sorry for the time it took to review it.
I think these are all great changes that are well documented, and they will make the life of azure users easier.
@pi0 will then need to review it and approve it before it gets merged.

docs/content/2.deploy/providers/azure.md Outdated Show resolved Hide resolved
docs/content/2.deploy/providers/azure.md Outdated Show resolved Hide resolved
// Attempt to load custom config
let customConfig = {};
try {
customConfig = JSON.parse(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can fail silently if JSON.parse fails (invalid json).
Maybe we should actually throw an error if JSON.parse fails ?
One way to do it would be to check if the file exist first.

const customConfig = exists ? JSON.parse() : {}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would get rid of the try-catch block and let the operation fail immediately instead of continuing with an invalid json

src/presets/azure.ts Outdated Show resolved Hide resolved
test/fixture/custom.staticwebapp.config.json Outdated Show resolved Hide resolved
@Hebilicious Hebilicious requested a review from pi0 July 17, 2023 08:01
@NicholasDawson
Copy link
Contributor Author

@Hebilicious I made fixes based on your feedback, let me know what you think

Copy link
Contributor

@Hebilicious Hebilicious left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would get rid of the try catch block entirely.
Otherwise this looks good to me.

@NicholasDawson
Copy link
Contributor Author

I would get rid of the try catch block entirely. Otherwise this looks good to me.

@Hebilicious All set.

@NicholasDawson
Copy link
Contributor Author

@Hebilicious do you know if this PR is ready to be merged, or does @pi0 need to review as well? Just wondering where it stands.

@Hebilicious
Copy link
Contributor

Pi is the code owner and has to review and merge all non documentation PRs.

@pi0 pi0 changed the title feat: enable azure preset to load custom config feat(azure): support custom configuration Aug 20, 2023
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for the PR ❀️ (and sorry it took long to review!)

I have made a couple of reactors to support via nitro.azure.config instead to avoid introducing second file and be consistent with other presets i hope you are happy with it.

@pi0 pi0 merged commit 4a6cbcb into nitrojs:main Aug 20, 2023
8 checks passed
@pi0 pi0 mentioned this pull request Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request preset:azure
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants