- 
                Notifications
    You must be signed in to change notification settings 
- Fork 132
Fix AddViteApp port configuration to use Aspire-assigned port #724
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
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            15 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      3e06c5c
              
                Initial plan for issue
              
              
                Copilot d959530
              
                Implement AddViteApp port configuration with command line arguments
              
              
                Copilot e9edf76
              
                Finalize AddViteApp port configuration and update example
              
              
                Copilot c2d7e81
              
                Improving on Copilots take
              
              
                aaronpowell 8ed59ff
              
                Keeping PORT on env vars
              
              
                aaronpowell 6040d2d
              
                Simplify AddViteApp port configuration by using vite.config.ts
              
              
                Copilot ac4d965
              
                Simplifying the code
              
              
                aaronpowell 8fa7f76
              
                Fixing test
              
              
                aaronpowell de2f20e
              
                Merge branch 'copilot/fix-718' of https://github.com/CommunityToolkit…
              
              
                aaronpowell 8d2f7aa
              
                Reverting a copilot change
              
              
                aaronpowell 56c930b
              
                Using an endpoint reference expression which is a better approach for…
              
              
                aaronpowell 2da789f
              
                Think we only need -- for npm, not other package managers
              
              
                aaronpowell ef4e6e9
              
                Cleaning up using statements
              
              
                aaronpowell 91305ae
              
                Remove automatic WithExternalHttpEndpoints from AddViteApp to let use…
              
              
                Copilot 5108520
              
                Merge branch 'main' into copilot/fix-718
              
              
                aaronpowell File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,6 +1,4 @@ | ||
| using Aspire.Hosting; | ||
| using Microsoft.AspNetCore.Http; | ||
| using System.Diagnostics; | ||
|  | ||
| namespace CommunityToolkit.Aspire.Hosting.NodeJS.Extensions.Tests; | ||
|  | ||
|  | @@ -141,7 +139,7 @@ public void ViteAppHasExposedHttpsEndpoints() | |
|  | ||
|  | ||
| [Fact] | ||
| public void ViteAppHasExposedExternalHttpEndpoints() | ||
| public void ViteAppDoesNotExposeExternalHttpEndpointsByDefault() | ||
| { | ||
| var builder = DistributedApplication.CreateBuilder(); | ||
|  | ||
|  | @@ -157,7 +155,7 @@ public void ViteAppHasExposedExternalHttpEndpoints() | |
|  | ||
| Assert.True(resource.TryGetAnnotationsOfType<EndpointAnnotation>(out var endpoints)); | ||
|  | ||
| Assert.Contains(endpoints, e => e.IsExternal); | ||
| Assert.DoesNotContain(endpoints, e => e.IsExternal); | ||
| } | ||
|  | ||
| [Fact] | ||
|  | @@ -195,4 +193,36 @@ public void WithNpmPackageInstallationCanUseCICommand() | |
| var resource = Assert.Single(appModel.Resources.OfType<NodeAppResource>()); | ||
| Assert.Equal("npm", resource.Command); | ||
| } | ||
|  | ||
| [Fact] | ||
| public void ViteAppConfiguresPortFromEnvironment() | ||
| { | ||
| var builder = DistributedApplication.CreateBuilder(); | ||
|  | ||
| builder.AddViteApp("vite"); | ||
|  | ||
| using var app = builder.Build(); | ||
|  | ||
| var appModel = app.Services.GetRequiredService<DistributedApplicationModel>(); | ||
|  | ||
| var resource = Assert.Single(appModel.Resources.OfType<NodeAppResource>()); | ||
|  | ||
| // Verify that command line arguments callback is configured | ||
| Assert.True(resource.TryGetAnnotationsOfType<CommandLineArgsCallbackAnnotation>(out var argsCallbackAnnotations)); | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. | ||
| List<object> args = []; | ||
| var ctx = new CommandLineArgsCallbackContext(args); | ||
|  | ||
| foreach (var annotation in argsCallbackAnnotations) | ||
| { | ||
| annotation.Callback(ctx); | ||
| } | ||
|  | ||
| Assert.Collection(args, | ||
| arg => Assert.Equal("run", arg), | ||
| arg => Assert.Equal("dev", arg), | ||
| arg => Assert.Equal("--", arg), | ||
| arg => Assert.Equal("--port", arg), | ||
| arg => Assert.IsType<EndpointReferenceExpression>(arg) | ||
| ); | ||
| } | ||
| } | ||
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Baking in WithExternalHttpEndpoints is probably a bad thing btw. We should revert that and let he user decide what to expose publicly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
.WithExternalHttpEndpoints()from both HTTP and HTTPS endpoint configurations in theAddViteAppmethod. Users now have full control over whether to expose endpoints externally. Updated the corresponding test to verify this behavior. (commit 91305ae)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree - the point of Vite is to create a website that can somehow be accessed, and when deployed that would need external HTTP(S) endpoints (in most scenarios - yes you could have them not public and have to handle IP allow listing/VPN/etc. so it can be accessed).
Aspire is full of opinionated defaults, and I think it's a pretty valid opinion that websites should have public endpoints.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imagine you were building a service with ingress proxy being your only public endpoint. We don’t make this assumption anywhere else because it’s something that the user should really do on their own. I do understand that it’s the least friction thing to do but baking in a security decision like this makes me super nervous.