public static int Main(string[] args) { var opts = new NancyOptions(); var app = Suave.Owin.OwinAppModule.OfMidFunc("/", NancyMiddleware.UseNancy(opts)); Web.startWebServer(Web.defaultConfig, app); return 0; }
/// <summary> /// Initializes a new instance of the <see cref="NancyOwinHost"/> class. /// </summary> /// <param name="next">Next middleware to run if necessary</param> /// <param name="options">The nancy options that should be used by the host.</param> public NancyOwinHost(Func <IDictionary <string, object>, Task> next, NancyOptions options) { this.next = next; this.options = options; options.Bootstrapper.Initialise(); this.engine = options.Bootstrapper.GetEngine(); }
/// <summary> /// Adds Nancy to the OWIN pipeline. /// </summary> /// <param name="builder">The application builder.</param> /// <param name="options">The Nancy options.</param> /// <returns>IAppBuilder.</returns> public static IAppBuilder UseNancy(this IAppBuilder builder, NancyOptions options = null) { NancyOptions nancyOptions = options ?? new NancyOptions(); AppBuilderExtensions.HookDisposal(builder, nancyOptions); return(builder.Use(NancyMiddleware.UseNancy(nancyOptions), new object[0])); }
public static App Initialize(AppConfig config, Func<StartOptions, NancyOptions, IDisposable> hostFunc) { config.ThrowIfInvalid(); var poller = new LeaderInfoPoller(config.StorageAccount); var startOptions = new StartOptions(); startOptions.Urls.Add(config.InternalUri); startOptions.Urls.Add(config.PublicUri); var auth = LoadAuth.LoadFromStorageAccount(config.StorageAccount); AddSystemAccess(auth, config.StorageAccount.GetSysPassword()); var api = ApiImplementation.Create(config.StorageAccount, poller, auth); var nancyOptions = new NancyOptions { Bootstrapper = new NancyBootstrapper(api, new UserValidator(auth)) }; var nodeInfo = new LeaderInfo(config.InternalUri); var selector = new LeaderLock(config.StorageAccount, nodeInfo, api); var cts = new CancellationTokenSource(); // fire up leader and scheduler first var tasks = new List<Task> { selector.KeepTryingToAcquireLock(cts.Token), poller.KeepPollingForLeaderInfo(cts.Token), }; // bind the API var host = hostFunc(startOptions, nancyOptions); return new App(host, cts, tasks); }
/// <summary> /// Adds Nancy to the OWIN pipeline. /// </summary> /// <param name="builder">The application builder.</param> /// <param name="configuration">A configuration builder action.</param> /// <returns>IAppBuilder.</returns> public static IAppBuilder UseNancy(this IAppBuilder builder, Action <NancyOptions> configuration) { NancyOptions nancyOptions = new NancyOptions(); configuration(nancyOptions); return(builder.UseNancy(nancyOptions)); }
/// <summary> /// Use Nancy in an OWIN pipeline /// </summary> /// <param name="configuration">A delegate to configure the <see cref="NancyOptions"/>.</param> /// <returns>An OWIN middleware delegate.</returns> public static MidFunc UseNancy(Action <NancyOptions> configuration) { var options = new NancyOptions(); configuration(options); return(UseNancy(options)); }
public void Configuration(IAppBuilder app) { var option = new NancyOptions { Bootstrapper = new Bootstrapper(), PerformPassThrough = context => context.Response.StatusCode == HttpStatusCode.NotFound }; //option.PassThroughWhenStatusCodesAre(HttpStatusCode.ServiceUnavailable); app.UseNancy(option); //app.UseNancy(); app.Map("/core", coreApp => { coreApp.UseIdentityServer(new IdentityServerOptions { SiteName = "Standalone Identity Server", SigningCertificate = Certificate.Get(), Factory = new IdentityServerServiceFactory() .UseInMemoryClients(Clients.Get()) .UseInMemoryScopes(Scopes.Get()) .UseInMemoryUsers(Users.Get()) }); }); }
private static Task OnComponent(IDictionary<string, object> env, Func<IDictionary<string, object>, Task> next) { var nancyOptions = new NancyOptions { Bootstrapper = new DefaultNancyBootstrapper() }; var nancyHost = new NancyOwinHost(next, nancyOptions); return nancyHost.Invoke(env); }
/// <summary> /// Adds Nancy to the OWIN pipeline. /// </summary> /// <param name="builder">The application builder delegate.</param> /// <param name="action">A configuration builder action.</param> /// <returns>The application builder delegate.</returns> public static Action<MidFunc> UseNancy(this Action<MidFunc> builder, Action<NancyOptions> action) { var options = new NancyOptions(); action(options); return builder.UseNancy(options); }
/// <summary> /// Adds Nancy to the OWIN pipeline. /// </summary> /// <param name="builder">The application builder delegate.</param> /// <param name="options">The Nancy options.</param> /// <returns>The application builder delegate.</returns> public static Action<MidFunc> UseNancy(this Action<MidFunc> builder, NancyOptions options = null) { var nancyOptions = options ?? new NancyOptions(); builder(NancyMiddleware.UseNancy(nancyOptions).Invoke); return builder; }
/// <summary> /// Adds Nancy to the OWIN pipeline. /// </summary> /// <param name="builder">The application builder delegate.</param> /// <param name="action">A configuration builder action.</param> /// <returns>The application builder delegate.</returns> public static Action <MidFunc> UseNancy(this Action <MidFunc> builder, Action <NancyOptions> action) { var options = new NancyOptions(); action(options); return(builder.UseNancy(options)); }
/// <summary> /// Adds Nancy to the OWIN pipeline. /// </summary> /// <param name="builder">The application builder delegate.</param> /// <param name="options">The Nancy options.</param> /// <returns>The application builder delegate.</returns> public static Action <MidFunc> UseNancy(this Action <MidFunc> builder, NancyOptions options = null) { var nancyOptions = options ?? new NancyOptions(); builder(NancyMiddleware.UseNancy(nancyOptions).Invoke); return(builder); }
/// <summary> /// Adds Nancy to the OWIN pipeline. /// </summary> /// <param name="builder">The application builder.</param> /// <param name="options">The Nancy options.</param> /// <returns>IAppBuilder.</returns> public static IAppBuilder UseNancy(this IAppBuilder builder, NancyOptions options = null) { var nancyOptions = options ?? new NancyOptions(); HookDisposal(builder, nancyOptions); return builder.Use(NancyMiddleware.UseNancy(nancyOptions)); }
public static IAppBuilder UseNancy(this IAppBuilder builder, NancyOptions options = null) { var nancyOptions = options ?? new NancyOptions(); HookDisposal(builder, nancyOptions); return builder.Use(typeof(NancyOwinHost), nancyOptions); }
/// <summary> /// Use Nancy in an OWIN pipeline /// </summary> /// <param name="options">An <see cref="NancyOptions"/> to configure the Nancy middleware</param> /// <returns>An OWIN middleware delegate.</returns> public static MidFunc UseNancy(NancyOptions options = null) { options = options ?? new NancyOptions(); options.Bootstrapper.Initialise(); var engine = options.Bootstrapper.GetEngine(); return (next => environment => { var owinRequestMethod = Get <string>(environment, "owin.RequestMethod"); var owinRequestScheme = Get <string>(environment, "owin.RequestScheme"); var owinRequestHeaders = Get <IDictionary <string, string[]> >(environment, "owin.RequestHeaders"); var owinRequestPathBase = Get <string>(environment, "owin.RequestPathBase"); var owinRequestPath = Get <string>(environment, "owin.RequestPath"); var owinRequestQueryString = Get <string>(environment, "owin.RequestQueryString"); var owinRequestBody = Get <Stream>(environment, "owin.RequestBody"); var owinRequestProtocol = Get <string>(environment, "owin.RequestProtocol"); var owinCallCancelled = Get <CancellationToken>(environment, "owin.CallCancelled"); var owinRequestHost = GetHeader(owinRequestHeaders, "Host") ?? Dns.GetHostName(); var owinUser = GetUser(environment); byte[] certificate = null; if (options.EnableClientCertificates) { var clientCertificate = Get <X509Certificate>(environment, "ssl.ClientCertificate"); certificate = (clientCertificate == null) ? null : clientCertificate.GetRawCertData(); } var serverClientIp = Get <string>(environment, "server.RemoteIpAddress"); var url = CreateUrl(owinRequestHost, owinRequestScheme, owinRequestPathBase, owinRequestPath, owinRequestQueryString); var nancyRequestStream = new RequestStream(owinRequestBody, ExpectedLength(owinRequestHeaders), StaticConfiguration.DisableRequestStreamSwitching ?? false); var nancyRequest = new Request( owinRequestMethod, url, nancyRequestStream, owinRequestHeaders.ToDictionary(kv => kv.Key, kv => (IEnumerable <string>)kv.Value, StringComparer.OrdinalIgnoreCase), serverClientIp, certificate, owinRequestProtocol); var tcs = new TaskCompletionSource <int>(); engine.HandleRequest( nancyRequest, StoreEnvironment(environment, owinUser), RequestComplete(environment, options.PerformPassThrough, next, tcs), RequestErrored(tcs), owinCallCancelled); return tcs.Task; }); }
public void Attach(IAppBuilder appBuilder) { var options = new NancyOptions { Bootstrapper = _nancyBootstrapper, PerformPassThrough = context => context.Request.Path.StartsWith("/signalr") }; appBuilder.UseNancy(options); }
/// <summary> /// Use Nancy in an OWIN pipeline /// </summary> /// <param name="options">An <see cref="NancyOptions"/> to configure the Nancy middleware</param> /// <returns>An OWIN middleware delegate.</returns> public static MidFunc UseNancy(NancyOptions options = null) { options = options ?? new NancyOptions(); options.Bootstrapper.Initialise(); var engine = options.Bootstrapper.GetEngine(); return (next => async environment => { var owinRequestMethod = Get <string>(environment, "owin.RequestMethod"); var owinRequestScheme = Get <string>(environment, "owin.RequestScheme"); var owinRequestHeaders = Get <IDictionary <string, string[]> >(environment, "owin.RequestHeaders"); var owinRequestPathBase = Get <string>(environment, "owin.RequestPathBase"); var owinRequestPath = Get <string>(environment, "owin.RequestPath"); var owinRequestQueryString = Get <string>(environment, "owin.RequestQueryString"); var owinRequestBody = Get <Stream>(environment, "owin.RequestBody"); var owinRequestProtocol = Get <string>(environment, "owin.RequestProtocol"); var owinCallCancelled = Get <CancellationToken>(environment, "owin.CallCancelled"); var owinRequestHost = GetHeader(owinRequestHeaders, "Host") ?? Dns.GetHostName(); var owinUser = GetUser(environment); X509Certificate2 certificate = null; if (options.EnableClientCertificates) { certificate = new X509Certificate2(Get <X509Certificate>(environment, "ssl.ClientCertificate").Export(X509ContentType.Cert)); } var serverClientIp = Get <string>(environment, "server.RemoteIpAddress"); var url = CreateUrl(owinRequestHost, owinRequestScheme, owinRequestPathBase, owinRequestPath, owinRequestQueryString); var expectedLength = ExpectedLength(owinRequestHeaders); // If length is 0 just use empty memory stream; as there is no body var nancyRequestStream = (expectedLength == 0) ? (Stream) new MemoryStream() : new RequestStream(owinRequestBody, expectedLength ?? 0, StaticConfiguration.DisableRequestStreamSwitching ?? false); var nancyRequest = new Request( owinRequestMethod, url, nancyRequestStream, owinRequestHeaders.ToDictionary(kv => kv.Key, kv => (IEnumerable <string>)kv.Value, StringComparer.OrdinalIgnoreCase), serverClientIp, certificate, owinRequestProtocol); var nancyContext = await engine.HandleRequest( nancyRequest, StoreEnvironment(environment, owinUser), owinCallCancelled).ConfigureAwait(false); await RequestComplete(nancyContext, environment, options.PerformPassThrough, next).ConfigureAwait(false); }); }
private static void HookDisposal(IAppBuilder builder, NancyOptions nancyOptions) { if (!builder.Properties.ContainsKey("host.OnAppDisposing")) { return; } CancellationToken?cancellationToken = builder.Properties["host.OnAppDisposing"] as CancellationToken?; if (cancellationToken.HasValue) { cancellationToken.Value.Register(new Action(nancyOptions.Bootstrapper.Dispose)); } }
public static IAppBuilder UseNancy(this IAppBuilder builder, NancyOptions options = null) { var nancyOptions = options ?? new NancyOptions(); var appDisposing = builder.Properties["host.OnAppDisposing"] as CancellationToken?; if (appDisposing.HasValue) { appDisposing.Value.Register(nancyOptions.Bootstrapper.Dispose); } return builder.Use(typeof(NancyOwinHost), nancyOptions); }
public void When_response_status_code_match_then_should_perform_pass_through() { // Given var options = new NancyOptions(); options.PassThroughWhenStatusCodesAre(HttpStatusCode.NotFound); var nancyContext = new NancyContext { Response = new Response {StatusCode = HttpStatusCode.NotFound} }; // When bool passedThrough = options.PerformPassThrough(nancyContext); // Then passedThrough.ShouldBeTrue(); }
private static void HookDisposal(IAppBuilder builder, NancyOptions nancyOptions) { if (!builder.Properties.ContainsKey(AppDisposingKey)) { return; } var appDisposing = builder.Properties[AppDisposingKey] as CancellationToken?; if (appDisposing.HasValue) { appDisposing.Value.Register(nancyOptions.Bootstrapper.Dispose); } }
public static App Initialize(AppConfig config) { var startOptions = new StartOptions(); startOptions.Urls.Add(config.InternalUri); startOptions.Urls.Add(config.PublicUri); var nancyOptions = new NancyOptions { Bootstrapper = new VaultBootstrapper() }; var cts = new CancellationTokenSource(); var webApp = WebApp.Start(startOptions, x => x.UseNancy(nancyOptions)); return new App(webApp, cts); }
static void Main() { var nancyOptions = new NancyOptions { Bootstrapper = new DefaultNancyBootstrapper() }; var app = new Fixer() .Use((env, next) => new NancyOwinHost(next, nancyOptions).Invoke(env)) .Build(); // Set up the Nowin server var builder = ServerBuilder.New() .SetPort(8888) .SetOwinApp(app); // Run using (builder.Start()) { Console.WriteLine("Listening on port 1337. Enter to exit."); Console.ReadLine(); } }
public static void PassThroughWhenStatusCodesAre(this NancyOptions nancyOptions, params HttpStatusCode[] httpStatusCode) { nancyOptions.PerformPassThrough = context => httpStatusCode.Any(code => context.Response.StatusCode == code); }
private static void Configuration(NancyOptions nancyOptions) { nancyOptions.Bootstrapper = new Bootstrapper(); }
private void SetupNancy(IAppBuilder app, IKernel kernel) { var bootstrapper = new EmailRNinjectNancyBootstrapper(kernel); var options = new NancyOptions {Bootstrapper = bootstrapper}; app.UseNancy(options); }
public static IAppBuilder UseNancy(this IAppBuilder builder, Action<NancyOptions> configuration) { var options = new NancyOptions(); configuration(options); return UseNancy(builder, options); }
public NancyOptionsFixture() { this.nancyOptions = new NancyOptions(); }
public static IAppBuilder UseNancy(this IAppBuilder builder, NancyOptions options = null) { return builder.Use(typeof(NancyOwinHost), options ?? new NancyOptions()); }
private static void Configuration(NancyOptions nancyOptions) { // Make sure to reference nancy project to get the right bootstrapper! nancyOptions.Bootstrapper = new Bootstrapper(); }