mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.8 KiB
62 lines
1.8 KiB
// ==========================================================================
|
|
// 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)
|
|
{
|
|
var request = context.HttpContext.Request;
|
|
|
|
if (!request.PathBase.HasValue || !request.PathBase.Value.EndsWith("/api", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
context.Result = new RedirectResult("/");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|