summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/StardewModdingAPI.Web/Controllers/ModsController.cs5
-rw-r--r--src/StardewModdingAPI.Web/Startup.cs17
2 files changed, 18 insertions, 4 deletions
diff --git a/src/StardewModdingAPI.Web/Controllers/ModsController.cs b/src/StardewModdingAPI.Web/Controllers/ModsController.cs
index 50c23b99..a3f5001a 100644
--- a/src/StardewModdingAPI.Web/Controllers/ModsController.cs
+++ b/src/StardewModdingAPI.Web/Controllers/ModsController.cs
@@ -12,7 +12,6 @@ using StardewModdingAPI.Web.Models;
namespace StardewModdingAPI.Web.Controllers
{
/// <summary>Provides an API to perform mod update checks.</summary>
- [Route("api/v1.0/mods")]
[Produces("application/json")]
public class ModsController : Controller
{
@@ -55,7 +54,7 @@ namespace StardewModdingAPI.Web.Controllers
[HttpGet]
public async Task<IDictionary<string, ModInfoModel>> GetAsync(string modKeys)
{
- return await this.Post(new ModSearchModel
+ return await this.PostAsync(new ModSearchModel
{
ModKeys = modKeys?.Split(',').Select(p => p.Trim()).ToArray() ?? new string[0]
});
@@ -64,7 +63,7 @@ namespace StardewModdingAPI.Web.Controllers
/// <summary>Fetch version metadata for the given mods.</summary>
/// <param name="search">The search options.</param>
[HttpPost]
- public async Task<IDictionary<string, ModInfoModel>> Post([FromBody] ModSearchModel search)
+ public async Task<IDictionary<string, ModInfoModel>> PostAsync([FromBody] ModSearchModel search)
{
// sort & filter keys
string[] modKeys = (search.ModKeys ?? new string[0])
diff --git a/src/StardewModdingAPI.Web/Startup.cs b/src/StardewModdingAPI.Web/Startup.cs
index fbe2bd92..b668c63e 100644
--- a/src/StardewModdingAPI.Web/Startup.cs
+++ b/src/StardewModdingAPI.Web/Startup.cs
@@ -60,7 +60,22 @@ namespace StardewModdingAPI.Web
loggerFactory.AddDebug();
app
.UseRewriter(new RewriteOptions().Add(new RewriteSubdomainRule())) // convert subdomain.smapi.io => smapi.io/subdomain for routing
- .UseMvc();
+ .UseMvc(route =>
+ {
+ route.MapRoute(
+ name: "API",
+ template: "api/{version}/{controller}/{action?}",
+ defaults: new
+ {
+ action = "GetAsync"
+ },
+ constraints: new
+ {
+ // version regex from SMAPI's SemanticVersion implementation
+ version = @"^v(?>(?<major>0|[1-9]\d*))\.(?>(?<minor>0|[1-9]\d*))(?>(?:\.(?<patch>0|[1-9]\d*))?)(?:-(?<prerelease>(?>[a-z0-9]+[\-\.]?)+))?$"
+ }
+ );
+ });
}
}
}