toenuff / flancy

A micro web framework for Windows PowerShell
MIT License
189 stars 21 forks source link

Support serving static content #17

Closed beatcracker closed 8 years ago

beatcracker commented 8 years ago

Currently, the only way to serve static content is to do something like this:

script = {[System.IO.File]::ReadAllText('c:\path\to\file.txt')}

It would be great, if webschema could be extended to support Nancy's static content serving.

toenuff commented 8 years ago

This sounds like a good idea. I'm just wondering whether or not I should be the one validating that those exist at runtime with test-path. I'm thinking no in case content is generated on the fly. My guess it will 404 if it doesn't exist - I'll add a test for that actually to be sure.

Now to consider whether those hashes should exist in a single web schema or passed in via StaticPaths.

Guess it's still a collection of hashes since we need the route and the target. Perhaps I can do something like this:

@{
   route = '/coolstuff'
   target = 'c:\hiddencoolstuff' #assuming that full paths are the way they are specified
   type = 'staticdir'
}, @{
   route = '/favicon.ico
   target = 'c:\hiddencoolstuff\logo.ico' #assuming that full paths are the way they are specified
   type = 'staticfile'
}

I could abuse the verb property instead of adding the new type property, but that would be abusing it

For completeness, here is the link to the Nancy docs for this: https://github.com/NancyFx/Nancy/wiki/Managing-static-content

beatcracker commented 8 years ago

Just to be clear: I'd be happy enough with almost any solution, but lacking C# experience I can't comment on an implemenation details.

toenuff commented 8 years ago

So now that we have the dsl, this will look like this:

new-flancy -webschema @(
     staticfile '/blah.html' '/blah/index.html'
     staticdir '/blah' 'blah/files' #not sure of the syntax here yet - have to see how they work
)
toenuff commented 8 years ago

I wound up having to add a -Path parameter to new-flancy to select the path where flancy is serving from. It's not as simple as just changing directory and creating the flancy. It has to be done in Nancy code with a few overrides. However, it's all done and I think it works pretty nicely.