mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-24 18:47:30 +00:00
Move packages under top-level 'src' folder
This commit is contained in:
1
src/Microsoft.AspNet.SpaServices/.gitignore
vendored
Normal file
1
src/Microsoft.AspNet.SpaServices/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/bin/
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0.23107" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.23107</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>4624f728-6dff-44b6-93b5-3c7d9c94bf3f</ProjectGuid>
|
||||
<RootNamespace>Microsoft.AspNet.SpaServices</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
||||
32
src/Microsoft.AspNet.SpaServices/SpaRouteConstraint.cs
Normal file
32
src/Microsoft.AspNet.SpaServices/SpaRouteConstraint.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Routing;
|
||||
|
||||
namespace Microsoft.AspNet.SpaServices
|
||||
{
|
||||
internal class SpaRouteConstraint : IRouteConstraint
|
||||
{
|
||||
private readonly string clientRouteTokenName;
|
||||
|
||||
public SpaRouteConstraint(string clientRouteTokenName) {
|
||||
if (string.IsNullOrEmpty(clientRouteTokenName)) {
|
||||
throw new ArgumentException("Value cannot be null or empty", "clientRouteTokenName");
|
||||
}
|
||||
|
||||
this.clientRouteTokenName = clientRouteTokenName;
|
||||
}
|
||||
|
||||
public bool Match(HttpContext httpContext, IRouter route, string routeKey, IDictionary<string, object> values, RouteDirection routeDirection)
|
||||
{
|
||||
var clientRouteValue = (values[this.clientRouteTokenName] as string) ?? string.Empty;
|
||||
return !HasDotInLastSegment(clientRouteValue);
|
||||
}
|
||||
|
||||
private bool HasDotInLastSegment(string uri)
|
||||
{
|
||||
var lastSegmentStartPos = uri.LastIndexOf('/');
|
||||
return uri.IndexOf('.', lastSegmentStartPos + 1) >= 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
53
src/Microsoft.AspNet.SpaServices/SpaRouteExtensions.cs
Normal file
53
src/Microsoft.AspNet.SpaServices/SpaRouteExtensions.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Routing;
|
||||
using Microsoft.AspNet.SpaServices;
|
||||
|
||||
// Putting in this namespace so it's always available whenever MapRoute is
|
||||
namespace Microsoft.AspNet.Builder
|
||||
{
|
||||
public static class SpaRouteExtensions
|
||||
{
|
||||
private const string ClientRouteTokenName = "clientRoute";
|
||||
|
||||
public static void MapSpaFallbackRoute(this IRouteBuilder routeBuilder, string name, object defaults, object constraints = null, object dataTokens = null)
|
||||
{
|
||||
MapSpaFallbackRoute(routeBuilder, name, /* templatePrefix */ (string)null, defaults, constraints, dataTokens);
|
||||
}
|
||||
|
||||
public static void MapSpaFallbackRoute(this IRouteBuilder routeBuilder, string name, string templatePrefix, object defaults, object constraints = null, object dataTokens = null)
|
||||
{
|
||||
var template = CreateRouteTemplate(templatePrefix);
|
||||
|
||||
var constraintsDict = ObjectToDictionary(constraints);
|
||||
constraintsDict.Add(ClientRouteTokenName, new SpaRouteConstraint(ClientRouteTokenName));
|
||||
|
||||
routeBuilder.MapRoute(name, template, defaults, constraintsDict, dataTokens);
|
||||
}
|
||||
|
||||
private static string CreateRouteTemplate(string templatePrefix)
|
||||
{
|
||||
templatePrefix = templatePrefix ?? string.Empty;
|
||||
|
||||
if (templatePrefix.Contains("?")) {
|
||||
// TODO: Consider supporting this. The {*clientRoute} part should be added immediately before the '?'
|
||||
throw new ArgumentException("SPA fallback route templates don't support querystrings");
|
||||
}
|
||||
|
||||
if (templatePrefix.Contains("#")) {
|
||||
throw new ArgumentException("SPA fallback route templates should not include # characters. The hash part of a URI does not get sent to the server.");
|
||||
}
|
||||
|
||||
if (templatePrefix != string.Empty && !templatePrefix.EndsWith("/")) {
|
||||
templatePrefix += "/";
|
||||
}
|
||||
|
||||
return templatePrefix + $"{{*{ ClientRouteTokenName }}}";
|
||||
}
|
||||
|
||||
private static IDictionary<string, object> ObjectToDictionary(object value)
|
||||
{
|
||||
return value as IDictionary<string, object> ?? new RouteValueDictionary(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
23
src/Microsoft.AspNet.SpaServices/project.json
Normal file
23
src/Microsoft.AspNet.SpaServices/project.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"version": "1.0.0-alpha7-1",
|
||||
"description": "Microsoft.AspNet.SpaServices",
|
||||
"authors": [
|
||||
"Microsoft"
|
||||
],
|
||||
"tags": [
|
||||
""
|
||||
],
|
||||
"projectUrl": "",
|
||||
"licenseUrl": "",
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
|
||||
"Microsoft.AspNet.Routing": "1.0.0-rc1-final"
|
||||
},
|
||||
"frameworks": {
|
||||
"net451": { },
|
||||
"dotnet5.4": {
|
||||
"dependencies": {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user