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

Support for changing Server Root Path, both Literal and Relative #248

Closed
Badgerati opened this issue May 9, 2019 · 4 comments · Fixed by #249
Closed

Support for changing Server Root Path, both Literal and Relative #248

Badgerati opened this issue May 9, 2019 · 4 comments · Fixed by #249
Assignees
Milestone

Comments

@Badgerati
Copy link
Owner

When Pode starts the server's root path is set the $MyInvocation.PSScriptRoot path, which defines the base path to the /views, /public and /errors directories.

Normally this is perfectly fine, but there are times when you need to alter the root path to your server because those directories above are located in a further subdirectory - or parent directory. Such a case could be when hosting your Pode server as a module, and the root path is set from the invocation of your module and not the Pode server.

  • Should be configurable using the pode.json file - as server.root
  • Support both literal and relative paths (testing if new path exists)
    • If relative, the path should be joined onto the invocation path (Join-Path)
    • If literal, use the supplied path instead of the invocation path
    • If none, just use the already default of the invocation path
@LLIT
Copy link

LLIT commented May 9, 2019

How about /routes to auto include .ps1 files.

I do it like this:

$RootPath   = $PSScriptRoot
$RouteFiles = @()
$RoutePath  = (Join-Path -Path $RootPath -ChildPath "Routes")
if (Test-Path $RoutePath) {
    Get-ChildItem -Path $RoutePath -Recurse -Filter *.ps1 | ForEach-Object {
        $RouteFiles += $_.FullName
        Write-Host $_.FullName
    }
}
Server -Threads 2 {
    listen *:8085 http
    engine pode
    
    $RouteFiles | ForEach-Object {
        . $_
    }
}

@Badgerati
Copy link
Owner Author

That's a pretty neat idea for another feature - though it could be dangerous for people that already have a /routes directory, like yourself 😛

For this change, it's purely to help fix issues where the views/public/errors directories can't be found by Pode because the invocation path gets a little screwy - happens when starting the server within another function within another module, and the /views are one level deeper than the invocation path.

Badgerati added a commit that referenced this issue May 9, 2019
@Badgerati Badgerati added this to the 0.29.0 milestone May 9, 2019
Badgerati added a commit that referenced this issue May 10, 2019
Resolves #248 - Ability to alter a server's root path
@jeremymcgee73
Copy link

This worked for me! The only strange thing is that the json file has to be in the same path as the script/module calling it. So my json file for pode is in my "public" function directory. Thanks for adding this!

@Badgerati
Copy link
Owner Author

@jeremymcgee73
Ah, of course! I can add a -RootPath parameter to the server function then, same logic as the config just in code 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants