Exemple #1
0
        public override void Start()
        {
            var host = Environment.Host;

            // Register all controller routes in mvc framework
            host.RouteBuilder.MapWebApiRoute(Defines.Resource.Guid, $"{Defines.PATH}/{{id?}}", new { controller = "HttpRedirect" });

            // Self
            Environment.Hal.ProvideLink(Defines.Resource.Guid, "self", doc => new { href = RedirectHelper.GetLocation(doc.id) });

            // Web Server
            Environment.Hal.ProvideLink(WebServer.Defines.Resource.Guid, Defines.Resource.Name, _ => {
                var id = GetDefaultDocumentId(null, null);
                return(new { href = RedirectHelper.GetLocation(id.Uuid) });
            });

            // Site
            Environment.Hal.ProvideLink(Sites.Defines.Resource.Guid, Defines.Resource.Name, site => {
                var siteId = new SiteId((string)site.id);
                Site s     = SiteHelper.GetSite(siteId.Id);
                var id     = GetDefaultDocumentId(s, "/");
                return(new { href = RedirectHelper.GetLocation(id.Uuid) });
            });

            // Application
            Environment.Hal.ProvideLink(Applications.Defines.Resource.Guid, Defines.Resource.Name, app => {
                var appId = new ApplicationId((string)app.id);
                Site s    = SiteHelper.GetSite(appId.SiteId);
                var id    = GetDefaultDocumentId(s, appId.Path);
                return(new { href = RedirectHelper.GetLocation(id.Uuid) });
            });
        }
Exemple #2
0
        public async Task <object> Post()
        {
            if (RedirectHelper.IsFeatureEnabled())
            {
                throw new AlreadyExistsException(RedirectHelper.FEATURE);
            }

            await RedirectHelper.SetFeatureEnabled(true);

            dynamic settings = RedirectHelper.ToJsonModel(null, null);

            return(Created(RedirectHelper.GetLocation(settings.id), settings));
        }
Exemple #3
0
        public object Get()
        {
            Site   site = ApplicationHelper.ResolveSite();
            string path = ApplicationHelper.ResolvePath();

            if (path == null)
            {
                return(NotFound());
            }

            dynamic d = RedirectHelper.ToJsonModel(site, path);

            return(LocationChanged(RedirectHelper.GetLocation(d.id), d));
        }