mirror of https://github.com/Squidex/squidex.git
106 changed files with 287 additions and 196 deletions
@ -0,0 +1,60 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.AspNetCore.Mvc.Filters; |
|||
using Squidex.Domain.Apps.Entities.Apps; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.Commands; |
|||
|
|||
namespace Squidex.Web |
|||
{ |
|||
[Area("Api")] |
|||
[ApiController] |
|||
[ApiExceptionFilter] |
|||
[ApiModelValidation(false)] |
|||
public abstract class ApiController : Controller |
|||
{ |
|||
protected ICommandBus CommandBus { get; } |
|||
|
|||
protected IAppEntity App |
|||
{ |
|||
get |
|||
{ |
|||
var appFeature = HttpContext.Features.Get<IAppFeature>(); |
|||
|
|||
if (appFeature == null) |
|||
{ |
|||
throw new InvalidOperationException("Not in a app context."); |
|||
} |
|||
|
|||
return appFeature.App; |
|||
} |
|||
} |
|||
|
|||
protected Guid AppId |
|||
{ |
|||
get { return App.Id; } |
|||
} |
|||
|
|||
protected ApiController(ICommandBus commandBus) |
|||
{ |
|||
Guard.NotNull(commandBus, nameof(commandBus)); |
|||
|
|||
CommandBus = commandBus; |
|||
} |
|||
|
|||
public override void OnActionExecuting(ActionExecutingContext context) |
|||
{ |
|||
if (!context.HttpContext.Request.PathBase.StartsWithSegments("/api")) |
|||
{ |
|||
context.Result = new RedirectResult("/"); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<LangVersion>7.3</LangVersion> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> |
|||
<DebugType>full</DebugType> |
|||
<DebugSymbols>True</DebugSymbols> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Squidex.Domain.Apps.Entities\Squidex.Domain.Apps.Entities.csproj" /> |
|||
<ProjectReference Include="..\Squidex.Infrastructure\Squidex.Infrastructure.csproj" /> |
|||
</ItemGroup> |
|||
<PropertyGroup> |
|||
<CodeAnalysisRuleSet>..\..\Squidex.ruleset</CodeAnalysisRuleSet> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<AdditionalFiles Include="..\..\stylecop.json" Link="stylecop.json" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue