@@ -26,7 +26,7 @@ function Start-OpenPackage {
2626 [Parameter (ValueFromRemainingArguments )]
2727 [Alias (' Arguments' , ' Args' , ' At' , ' Url' , ' AtUri' , ' FilePath' , ' Repository' , ' Nuget' )]
2828 [PSObject []]
29- $ArgumentList ,
29+ $ArgumentList ,
3030
3131 # The root url.
3232 # By default, this will be automatically to a random local port.
@@ -50,12 +50,10 @@ function Start-OpenPackage {
5050 ([PSCustomObject ]@ {PSTypeName = ' OpenPackage.ContentTypeMap' }).TypeMap
5151 ),
5252
53- # If set, the scripts in the package will be invokable.
54- # This turns allows every PowerShell script in the package into server side code.
55- # This should be used cautiously, and only with known packages.
56- [Alias (' CanInvoke' , ' Invocable' )]
57- [switch ]$Invokable ,
58-
53+ # A Route Table
54+ [Collections.IDictionary ]
55+ $Route = [Ordered ]@ {},
56+
5957 # The throttle limit.
6058 # This is the number of concurrent jobs that can be running at once.
6159 [uint16 ]$ThrottleLimit = .5 kb ,
@@ -121,17 +119,11 @@ function Start-OpenPackage {
121119 if ($request.url.localPath -ne ' /' ) {
122120 [IO.Packaging.PackUriHelper ]::CreatePartUri($request.url.localPath )
123121 }
124- if ($Invokable ) {
125- [IO.Packaging.PackUriHelper ]::CreatePartUri(" $ ( $request.url.LocalPath ) .ps1" )
126- }
127- $noTrailingSlash = ($request.url.LocalPath -replace ' /$' )
128- if ($Invokable ) {
129- $noTrailingSlash + ' /index.ps1'
122+ if ($Route -and $route [$request.Url.LocalPath ]) {
123+ [IO.Packaging.PackUriHelper ]::CreatePartUri(" $ ( $route [$request.Url.LocalPath ]) " )
130124 }
131- if ($noTrailingSlash ) {
132- if ($Invokable ) {
133- [IO.Packaging.PackUriHelper ]::CreatePartUri(" $ ( $noTrailingSlash ) .ps1" )
134- }
125+ $noTrailingSlash = ($request.url.LocalPath -replace ' /$' )
126+ if ($noTrailingSlash ) {
135127 try {
136128 [IO.Packaging.PackUriHelper ]::CreatePartUri($noTrailingSlash )
137129 } catch {
@@ -146,8 +138,8 @@ function Start-OpenPackage {
146138 $noTrailingSlash + ' .html'
147139 $noTrailingSlash + ' .md'
148140 } elseif ($request.url.LocalPath ) {
149- if ($Invokable ) {
150- [IO.Packaging.PackUriHelper ]::CreatePartUri(" $ ( $request.url .LocalPath ) .ps1 " )
141+ if ($Route -and $route [ $request .Url.LocalPath ] ) {
142+ [IO.Packaging.PackUriHelper ]::CreatePartUri(" $ ( $route [ $ request.Url .LocalPath ] ) " )
151143 }
152144 try {
153145 [IO.Packaging.PackUriHelper ]::CreatePartUri($request.url.LocalPath )
@@ -191,7 +183,8 @@ function Start-OpenPackage {
191183 }
192184
193185 # If we are invokable and are dealing with a script file
194- if ($Invokable -and
186+ if ($Route -and
187+ @ ($route.Values ) -contains $packagePart.Uri -and
195188 $packagePart.Uri -match ' \.ps1$' -and
196189 $packagePart.Reader
197190 ) {
@@ -664,6 +657,12 @@ function Start-OpenPackage {
664657 $io.BufferSize = $BufferSize
665658 }
666659
660+ # If the IO does not have a route table
661+ if (-not $io.Route ) {
662+ # use the default route table (this should be empty)
663+ $io.Route = $Route
664+ }
665+
667666 # Now we're almost ready to serve,
668667 # it's time to send an event.
669668 # We need to prepare our message data with the relevant info
@@ -718,14 +717,7 @@ function Start-OpenPackage {
718717 # 1. It lets people know that a server is running
719718 # 2. It gives people something a link to click.
720719 Write-Warning " Listening on $rootUrl "
721- }
722-
723- # If the server is invokable
724- if ($Invokable ) {
725- # Write one more warning, with some exclamation points
726- # to get the seriousness across.
727- Write-Warning " ! ! ! Invokable on $rootUrl ! ! !"
728- }
720+ }
729721
730722 # If there was no package identifier
731723 if (-not $package.PackageProperties.Identifier ) {
0 commit comments