Created
March 17, 2016 05:25
-
-
Save anonymous/6726507d9378301f240a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNet.Builder; | |
using Microsoft.AspNet.Hosting; | |
using Microsoft.Extensions.DependencyInjection; | |
namespace MyAPI | |
{ | |
public class Startup | |
{ | |
//MS: Entry point for the application. | |
//KM: This function doesn't do anything useful except being required by Microsoft to do nothing useful. | |
//KM: Somehow it starts something somewhere, as if getting here didn't require starting something already. | |
public static void Main(string[] args) => WebApplication.Run<Startup>(args); | |
//MS: This method gets called by the runtime. Use this method to add services to the container. | |
//MS: For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 | |
//KM: More Microsoft BS requiring to create this method just to write a few lines of code to add some services, because we can't just write a few lines of code without stupid classes and methods. | |
//KM: No idea what's IServiceCollection and why we need it, but going with the flow. | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
//MS: Add framework services. | |
//KM: I guess this enables some MVC features, just no idea why we have to add the same thing again in the "Configure" class below. | |
services.AddMvc(); | |
//KM: Enable API/Controller access from all clients. | |
//KM: Haven't tested this yet, but it's supposed to allow this server (or specifically Controller) to accept external requests from any host or IP address. | |
//KM: Based on http://stackoverflow.com/questions/31942037/how-to-enable-cors-in-asp-net-5 | |
services.AddCors(options => options.AddPolicy("AllowAll", p => p.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader())); | |
} | |
//MS: This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | |
//KM: HTTP request pipeline my ass. Can't you learn plain English for God's sake? | |
//KM: I'm guessing this class is again needed just to add a few lines of code specifying some .NET features I may need to use. | |
//KM: No idea what's IApplicationBuilder and why we need it, but going with the flow. | |
public void Configure(IApplicationBuilder app) | |
{ | |
//KM: Guessing this is needed to run this app on IIS. KM:TODO:Figure out if we want to use IIS or how to replace it with Kestrel | |
app.UseIISPlatformHandler(); | |
//KM: I guess this also enables some MVC features | |
app.UseMvc(); | |
//KM: Include something named "Cors" to allow Controller to accept requests from external IPs. Because life would be too easy if anyone could just run anything they want from anywhere. | |
//KM: Based on http://stackoverflow.com/questions/31942037/how-to-enable-cors-in-asp-net-5 | |
app.UseCors("AllowAll"); | |
} | |
//Note: database connection string is stored in Globals.cs | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment