Headless CMS and Content Managment Hub
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.
 
 
 
 
 

58 lines
1.6 KiB

// ==========================================================================
// ControllerBase.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Squidex.Domain.Apps.Read.Apps;
using Squidex.Infrastructure;
using Squidex.Infrastructure.CQRS.Commands;
using Squidex.Pipeline;
namespace Squidex.Areas.Api.Controllers
{
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 string AppName
{
get { return App.Name; }
}
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 NotFoundResult();
}
}
}
}