<commit_before>using System;
using System.IO;
using ServiceStack.Api.Swagger;
using ServiceStack.Common.Web;
using ServiceStack.Text;
using ServiceStack.WebHost.Endpoints;
using Rainy.CustomHandler;
using Rainy.WebService;
using System.Web;
using ServiceStack.WebHost.Endpoints.Support;
using System.Linq;
using ServiceStack.ServiceHost;


using ServiceStack.ServiceHost;
using ServiceStack.Common;

namespace Rainy
{
	public delegate void ComposeObjectGraphDelegate (Funq.Container container);

	public class AppHost : AppHostHttpListenerBase
	{
		private ComposeObjectGraphDelegate ComposeObjectGraph;
		public AppHost (ComposeObjectGraphDelegate graph_composer) : base("Rainy", typeof(GetNotesRequest).Assembly)
		{
			this.ComposeObjectGraph = graph_composer;
		}

		public override void Configure (Funq.Container container)
		{
			this.ComposeObjectGraph (container);

			JsConfig.DateHandler = JsonDateHandler.ISO8601;

			Plugins.Add (new SwaggerFeature ());

			// register our custom exception handling
			this.ExceptionHandler = Rainy.ErrorHandling.ExceptionHandler.CustomExceptionHandler;
			this.ServiceExceptionHandler = Rainy.ErrorHandling.ExceptionHandler.CustomServiceExceptionHandler;

			var swagger_path = Path.Combine(Path.GetDirectoryName(this.GetType ().Assembly.Location), "../../swagger-ui/");
			var swagger_handler = new FilesystemHandler ("/swagger-ui/", swagger_path);

			IHttpHandlerDecider uihandler;
			if (JsonConfig.Config.Global.Development) {
				var adminui_path = Path.Combine(Path.GetDirectoryName(this.GetType ().Assembly.Location), "../../../Rainy.UI/dist/");
				uihandler = (IHttpHandlerDecider) new FilesystemHandler ("/ui/", adminui_path);
			} else {
				uihandler = (IHttpHandlerDecider) new EmbeddedResourceHandler ("/ui/", this.GetType ().Assembly, "Rainy.WebService.Admin.UI");
			}

			// BUG HACK
			// GlobalResponseHeaders are not cleared between creating instances of a new config
			// this will be fatal (duplicate key error) for unit tests so we clear the headers
			EndpointHostConfig.Instance.GlobalResponseHeaders.Clear ();

			SetConfig (new EndpointHostConfig {

				EnableFeatures = Feature.All.Remove (Feature.Metadata),
				DefaultRedirectPath = "/ui/manage.html",

				// not all tomboy clients send the correct content-type
				// so we force application/json
				DefaultContentType = ContentType.Json,

				RawHttpHandlers = { 
					swagger_handler.CheckAndProcess,
					uihandler.CheckAndProcess
				},

				// enable cors
				GlobalResponseHeaders = {
					{ "Access-Control-Allow-Origin", "*" },
					{ "Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS" },
					// time in seconds preflight responses can be cached by the client
					{ "Access-Control-Max-Age", "1728000" },
//					{ "Access-Control-Max-Age", "1" },

					// the Authority header must be whitelisted; it is sent be the rainy-ui
					// for authentication
					{ "Access-Control-Allow-Headers", "Content-Type, Authority" },
				}, 
			});
			
		}
	}
}<commit_msg>Enable CORS for web client<commit_after>using System;
using System.IO;
using ServiceStack.Api.Swagger;
using ServiceStack.Common.Web;
using ServiceStack.Text;
using ServiceStack.WebHost.Endpoints;
using Rainy.CustomHandler;
using Rainy.WebService;
using System.Web;
using ServiceStack.WebHost.Endpoints.Support;
using System.Linq;
using ServiceStack.ServiceHost;


using ServiceStack.ServiceHost;
using ServiceStack.Common;

namespace Rainy
{
	public delegate void ComposeObjectGraphDelegate (Funq.Container container);

	public class AppHost : AppHostHttpListenerBase
	{
		private ComposeObjectGraphDelegate ComposeObjectGraph;
		public AppHost (ComposeObjectGraphDelegate graph_composer) : base("Rainy", typeof(GetNotesRequest).Assembly)
		{
			this.ComposeObjectGraph = graph_composer;
		}

		public override void Configure (Funq.Container container)
		{
			this.ComposeObjectGraph (container);

			JsConfig.DateHandler = JsonDateHandler.ISO8601;

			Plugins.Add (new SwaggerFeature ());

			// register our custom exception handling
			this.ExceptionHandler = Rainy.ErrorHandling.ExceptionHandler.CustomExceptionHandler;
			this.ServiceExceptionHandler = Rainy.ErrorHandling.ExceptionHandler.CustomServiceExceptionHandler;

			var swagger_path = Path.Combine(Path.GetDirectoryName(this.GetType ().Assembly.Location), "../../swagger-ui/");
			var swagger_handler = new FilesystemHandler ("/swagger-ui/", swagger_path);

			IHttpHandlerDecider uihandler;
			if (JsonConfig.Config.Global.Development) {
				var adminui_path = Path.Combine(Path.GetDirectoryName(this.GetType ().Assembly.Location), "../../../Rainy.UI/dist/");
				uihandler = (IHttpHandlerDecider) new FilesystemHandler ("/ui/", adminui_path);
			} else {
				uihandler = (IHttpHandlerDecider) new EmbeddedResourceHandler ("/ui/", this.GetType ().Assembly, "Rainy.WebService.Admin.UI");
			}

			this.RequestFilters.Add ((req, resp, dto) => {
				if (req.HttpMethod == "OPTIONS") {
					resp.StatusCode = 200;
					resp.End ();
				}
			});

			// BUG HACK
			// GlobalResponseHeaders are not cleared between creating instances of a new config
			// this will be fatal (duplicate key error) for unit tests so we clear the headers
			EndpointHostConfig.Instance.GlobalResponseHeaders.Clear ();

			SetConfig (new EndpointHostConfig {

				EnableFeatures = Feature.All.Remove (Feature.Metadata),
				DefaultRedirectPath = "/ui/manage.html",

				// not all tomboy clients send the correct content-type
				// so we force application/json
				DefaultContentType = ContentType.Json,

				RawHttpHandlers = { 
					swagger_handler.CheckAndProcess,
					uihandler.CheckAndProcess
				},

				// enable cors
				GlobalResponseHeaders = {
					{ "Access-Control-Allow-Origin", "*" },
					{ "Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS" },
					// time in seconds preflight responses can be cached by the client
					{ "Access-Control-Max-Age", "1728000" },
//					{ "Access-Control-Max-Age", "1" },

					// the Authority header must be whitelisted; it is sent be the rainy-ui
					// for authentication
					{ "Access-Control-Allow-Headers", "Content-Type, Authority, AccessToken" },
				}, 
			});
			
		}
	}
}
{'fraction_non_alphanumeric': 0.10955372966006122, 'fraction_numerical': 0.0043499275012083135, 'mean_word_length': 4.01453957996769, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5238669', 'n_tokens_mistral': 2123, 'n_tokens_neox': 1779, 'n_words': 423}