44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
|
using System;
|
|||
|
using ln.http;
|
|||
|
using ln.http.resources;
|
|||
|
using System.IO;
|
|||
|
namespace ln.skyscanner.http
|
|||
|
{
|
|||
|
public class SkyScannerHttpApplication : ResourceApplication
|
|||
|
{
|
|||
|
public SkyScanner SkyScanner { get; }
|
|||
|
|
|||
|
public String BasePath { get; private set; }
|
|||
|
public String TemplatesBasePath => Path.Combine(BasePath, "templates","static");
|
|||
|
|
|||
|
|
|||
|
|
|||
|
public SkyScannerHttpApplication(SkyScanner skyScanner)
|
|||
|
{
|
|||
|
SkyScanner = skyScanner;
|
|||
|
|
|||
|
BasePath = Path.GetFullPath(".");
|
|||
|
|
|||
|
DirectoryResource staticTemplates = new DirectoryResource(RootResource, TemplatesBasePath);
|
|||
|
|
|||
|
staticTemplates.ResourceTypeHook = ResourceTypeHook;
|
|||
|
staticTemplates.DefaultResource = staticTemplates.GetResource("index.html");
|
|||
|
|
|||
|
RootResource.DefaultResource = staticTemplates;
|
|||
|
|
|||
|
|
|||
|
SkyScannerHttpApi api = new SkyScannerHttpApi(this);
|
|||
|
}
|
|||
|
|
|||
|
private Resource ResourceTypeHook(DirectoryResource directoryResource, FileInfo fileInfo)
|
|||
|
{
|
|||
|
if (fileInfo.Extension.Equals(".html"))
|
|||
|
return new TemplateResource(directoryResource, fileInfo.FullName);
|
|||
|
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|