mirror of
https://github.com/tomasvarg/OwinWebApiTest.git
synced 2026-03-01 08:28:49 +00:00
Added support for Web & Doc static file servers with rewrite rules prepared for SPA routing
This commit is contained in:
parent
aee4bd408e
commit
1fdd29c01a
10
OwinWebApiTest/Doc/index.html
Normal file
10
OwinWebApiTest/Doc/index.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title></title>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Documentation</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -76,6 +76,10 @@
|
|||||||
<HintPath>..\packages\Microsoft.Owin.Cors.3.1.0\lib\net45\Microsoft.Owin.Cors.dll</HintPath>
|
<HintPath>..\packages\Microsoft.Owin.Cors.3.1.0\lib\net45\Microsoft.Owin.Cors.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.Owin.FileSystems, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Microsoft.Owin.FileSystems.3.1.0\lib\net45\Microsoft.Owin.FileSystems.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Microsoft.Owin.Host.SystemWeb, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
<Reference Include="Microsoft.Owin.Host.SystemWeb, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Microsoft.Owin.Host.SystemWeb.3.1.0\lib\net45\Microsoft.Owin.Host.SystemWeb.dll</HintPath>
|
<HintPath>..\packages\Microsoft.Owin.Host.SystemWeb.3.1.0\lib\net45\Microsoft.Owin.Host.SystemWeb.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
@ -92,6 +96,10 @@
|
|||||||
<HintPath>..\packages\Microsoft.Owin.Security.OAuth.3.1.0\lib\net45\Microsoft.Owin.Security.OAuth.dll</HintPath>
|
<HintPath>..\packages\Microsoft.Owin.Security.OAuth.3.1.0\lib\net45\Microsoft.Owin.Security.OAuth.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.Owin.StaticFiles, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Microsoft.Owin.StaticFiles.3.1.0\lib\net45\Microsoft.Owin.StaticFiles.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
@ -138,9 +146,13 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Content Include="Doc\index.html" />
|
||||||
<Content Include="Web.config">
|
<Content Include="Web.config">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</Content>
|
</Content>
|
||||||
|
<Content Include="Web\app.js" />
|
||||||
|
<Content Include="Web\assets\whatever.html" />
|
||||||
|
<Content Include="Web\index.html" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="App_Start\WebApiConfig.cs" />
|
<Compile Include="App_Start\WebApiConfig.cs" />
|
||||||
|
|||||||
@ -1,10 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Configuration;
|
using System.Configuration;
|
||||||
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Owin;
|
using Owin;
|
||||||
using Microsoft.Owin;
|
using Microsoft.Owin;
|
||||||
using Microsoft.Owin.Cors;
|
using Microsoft.Owin.Cors;
|
||||||
using Microsoft.Owin.Security.OAuth;
|
using Microsoft.Owin.Security.OAuth;
|
||||||
|
using Microsoft.Owin.FileSystems;
|
||||||
|
using Microsoft.Owin.StaticFiles;
|
||||||
using System.Web.Http;
|
using System.Web.Http;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
|
||||||
@ -42,6 +45,31 @@ namespace OwinWebApiTest
|
|||||||
// allow self-signed certificates
|
// allow self-signed certificates
|
||||||
ServicePointManager.ServerCertificateValidationCallback +=
|
ServicePointManager.ServerCertificateValidationCallback +=
|
||||||
(sender, cert, chain, sslPolicyErrors) => true;
|
(sender, cert, chain, sslPolicyErrors) => true;
|
||||||
|
|
||||||
|
string webDir = ConfigurationManager.AppSettings["WebDirectory"];
|
||||||
|
if (string.IsNullOrEmpty(webDir)) webDir = "Web";
|
||||||
|
app.UseFileServer(GetFileServerOptions(PathString.Empty, webDir));
|
||||||
|
|
||||||
|
string docDir = ConfigurationManager.AppSettings["DocDirectory"];
|
||||||
|
if (string.IsNullOrEmpty(docDir)) docDir = "Doc";
|
||||||
|
app.UseFileServer(GetFileServerOptions(new PathString("/doc"), docDir));
|
||||||
|
}
|
||||||
|
|
||||||
|
private FileServerOptions GetFileServerOptions(PathString pathString, string dir)
|
||||||
|
{
|
||||||
|
string appRoot = AppDomain.CurrentDomain.BaseDirectory;
|
||||||
|
var fileSystem = new PhysicalFileSystem(Path.Combine(appRoot, dir));
|
||||||
|
|
||||||
|
var options = new FileServerOptions
|
||||||
|
{
|
||||||
|
RequestPath = pathString,
|
||||||
|
EnableDefaultFiles = true,
|
||||||
|
FileSystem = fileSystem
|
||||||
|
};
|
||||||
|
options.StaticFileOptions.FileSystem = fileSystem;
|
||||||
|
options.StaticFileOptions.ServeUnknownFileTypes = false;
|
||||||
|
|
||||||
|
return options;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,7 +28,25 @@
|
|||||||
<remove name="OPTIONSVerbHandler" />
|
<remove name="OPTIONSVerbHandler" />
|
||||||
<remove name="TRACEVerbHandler" />
|
<remove name="TRACEVerbHandler" />
|
||||||
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
|
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
|
||||||
|
<remove name="StaticFile"/>
|
||||||
|
<add name="Owin" verb="" path="*" type="Microsoft.Owin.Host.SystemWeb.OwinHttpHandler, Microsoft.Owin.Host.SystemWeb"/>
|
||||||
</handlers>
|
</handlers>
|
||||||
|
<rewrite>
|
||||||
|
<rules>
|
||||||
|
<rule name="Web client config - Single Page App and Docs" stopProcessing="true">
|
||||||
|
<match url=".*" />
|
||||||
|
<conditions logicalGrouping="MatchAll">
|
||||||
|
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
|
||||||
|
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
|
||||||
|
<add input="{REQUEST_URI}" pattern="^/.*[.].*" negate="true" />
|
||||||
|
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
|
||||||
|
<add input="{REQUEST_URI}" pattern="^/(assets)" negate="true" />
|
||||||
|
<add input="{REQUEST_URI}" pattern="^/(doc)" negate="true" />
|
||||||
|
</conditions>
|
||||||
|
<action type="Rewrite" url="/" />
|
||||||
|
</rule>
|
||||||
|
</rules>
|
||||||
|
</rewrite>
|
||||||
</system.webServer>
|
</system.webServer>
|
||||||
<runtime>
|
<runtime>
|
||||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
|
|||||||
1
OwinWebApiTest/Web/app.js
Normal file
1
OwinWebApiTest/Web/app.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
console.log("app started");
|
||||||
1
OwinWebApiTest/Web/assets/whatever.html
Normal file
1
OwinWebApiTest/Web/assets/whatever.html
Normal file
@ -0,0 +1 @@
|
|||||||
|
whatever content
|
||||||
11
OwinWebApiTest/Web/index.html
Normal file
11
OwinWebApiTest/Web/index.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title></title>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Application</h1>
|
||||||
|
<script src="app.js" type="text/javascript"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -14,10 +14,12 @@
|
|||||||
<package id="Microsoft.Net.Compilers" version="2.6.1" targetFramework="net452" developmentDependency="true" />
|
<package id="Microsoft.Net.Compilers" version="2.6.1" targetFramework="net452" developmentDependency="true" />
|
||||||
<package id="Microsoft.Owin" version="3.1.0" targetFramework="net452" />
|
<package id="Microsoft.Owin" version="3.1.0" targetFramework="net452" />
|
||||||
<package id="Microsoft.Owin.Cors" version="3.1.0" targetFramework="net452" />
|
<package id="Microsoft.Owin.Cors" version="3.1.0" targetFramework="net452" />
|
||||||
|
<package id="Microsoft.Owin.FileSystems" version="3.1.0" targetFramework="net452" />
|
||||||
<package id="Microsoft.Owin.Host.SystemWeb" version="3.1.0" targetFramework="net452" />
|
<package id="Microsoft.Owin.Host.SystemWeb" version="3.1.0" targetFramework="net452" />
|
||||||
<package id="Microsoft.Owin.Security" version="3.1.0" targetFramework="net452" />
|
<package id="Microsoft.Owin.Security" version="3.1.0" targetFramework="net452" />
|
||||||
<package id="Microsoft.Owin.Security.Cookies" version="3.1.0" targetFramework="net452" />
|
<package id="Microsoft.Owin.Security.Cookies" version="3.1.0" targetFramework="net452" />
|
||||||
<package id="Microsoft.Owin.Security.OAuth" version="3.1.0" targetFramework="net452" />
|
<package id="Microsoft.Owin.Security.OAuth" version="3.1.0" targetFramework="net452" />
|
||||||
|
<package id="Microsoft.Owin.StaticFiles" version="3.1.0" targetFramework="net452" />
|
||||||
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net452" />
|
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net452" />
|
||||||
<package id="Owin" version="1.0" targetFramework="net452" />
|
<package id="Owin" version="1.0" targetFramework="net452" />
|
||||||
</packages>
|
</packages>
|
||||||
Loading…
Reference in New Issue
Block a user