NancyFx / Nancy

Lightweight, low-ceremony, framework for building HTTP based services on .Net and Mono
http://nancyfx.org
MIT License
7.15k stars 1.47k forks source link

Create the Nancy Module via PowerShell and Classes. #2531

Open dotps1 opened 8 years ago

dotps1 commented 8 years ago

Prerequisites

I am trying to replicate the nancy functionality in PowerShell via Classes. I am able to create the object but the routes do not seem to work, I can see the routes exist on NancyModule object, but all I get is a 404 error.

Steps to Reproduce

Here is my code:

using namespace Nancy
using namespace Nancy.Hosting.Self
using namespace Nancy.Conventions

#Add-Type -Path ".\Nancy\lib\net40\Nancy.dll"
#Add-Type -Path ".\Nancy.Hosting.Self\lib\net40\Nancy.Hosting.Self.dll"

Class Pancy : Nancy.NancyModule {
    Pancy() {
        $this.Get["/"] = {
            Param (
                $args
            )

            return "Hello World!"
        }
    }

    [Void]Start([Uri]$Uri) {
        $nancyHost = [Nancy.Hosting.Self.NancyHost]::new($Uri)
        $nancyHost.Start()

        Read-Host "Nancy Server Started. Press Enter to exit"

        $nancyHost.Stop()
    }
}

Then I call it like this:

PS C:\> $pancy = [Pancy]::new()

PS C:\> $pancy.Start("http://localhost:8282")
Nancy Server Started. Press Enter to exit: 

But, I get a 404 when browsing to http://localhost:8282

but the object has a route:

PS C:\> $pancy.Routes.Description

Name        : 
Condition   : 
Description : 
Metadata    : 
Method      : GET
Path        : /
Segments    : 

System Configuration

dotps1 commented 7 years ago

Just wondering if there is any thoughts on this, its been a few months.

cemremengu commented 7 years ago

Other than being cool, I don't see why anyone would spend time on this (or maybe I am not smart enough to understand its purpose) :)

With the dotnet-cli you can do something similar anyways