npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng-miniprofiler

v0.0.4

Published

This package contains an Http interceptor for using MiniProfiler with Angular.

Downloads

190

Readme

NgMiniProfiler

This package contains an Http interceptor for using MiniProfiler with Angular.

Getting started

To use it in your app, simply import the MiniProfilerModule and provide the interceptor.

import { MiniProfilerModule, MiniProfilerInterceptor } from 'ng-miniprofiler';

@NgModule({
  [...]
  imports: [
    MiniProfilerModule.forRoot({
      baseUri: 'http://localhost:12345',
      colorScheme: 'Auto',
      maxTraces: 15,
      position: 'BottomLeft',
      toggleShortcut: 'Alt+M',
      enabled: true,
      enableGlobalMethod: true
    }),
  ],
  providers: [
    { provide: HTTP_INTERCEPTORS, useClass: MiniProfilerInterceptor, multi: true }
  ]
})
export class YourModule { }

Configurations

Ng-miniprofiler offers a couple of configurations.

| Config | Description | Default | | ------------------- |:---------------------------------------------------------------------------------------|---------| | baseUri | The base uri of the server hosting your MiniProfiler results and include.min.js file. Depending on your configs, the results may be under the profiling route. The value should then be http://localhost:12345/profiling. | '' | | colorScheme | The theme. Either Light, Dark or Auto. | Auto | | maxTraces | Maximum number of traces shown. | 15 | | position | Where the popup should be placed. Either Left, Right, BottomLeft, BottomRight. | Left | | toggleShortcut | The shortcut for toggling the popup. | Alt+M | | showControls | Whether or not the controls (minimize and clear) should be shown. | false | | enabled | Whether or not miniprofiler is enabled. | true | | enableGlobalMethod | Whether or not an enableMiniProfiler method should be added to the window object. Can be useful in a production environment where you want MiniProfiler to be disabed by default. | true |

Backend

If you are using asp.net core then you need to add two nuget packages :- MiniProfiler.AspNetCore.Mvc, MiniProfiler.EntityFrameworkCore

services.AddMiniProfiler(options =>
        {
            (options.Storage as MemoryCacheStorage).CacheDuration = TimeSpan.FromMinutes(60);

            // (Optional) Control which SQL formatter to use, InlineFormatter is the default
            options.SqlFormatter = new StackExchange.Profiling.SqlFormatters.InlineFormatter();

            // (Optional) You can disable "Connection Open()", "Connection Close()" (and async variant) tracking.
            // (defaults to true, and connection opening/closing is tracked)
            options.TrackConnectionOpenClose = true;

            // (Optional) Use something other than the "light" color scheme.
            // (defaults to "light")
            options.ColorScheme = StackExchange.Profiling.ColorScheme.Auto;

            // The below are newer options, available in .NET Core 3.0 and above:

            // (Optional) You can disable MVC filter profiling
            // (defaults to true, and filters are profiled)
            options.EnableMvcFilterProfiling = true;

            // (Optional) You can disable MVC view profiling
            // (defaults to true, and views are profiled)
            options.EnableMvcViewProfiling = true;
        }).AddEntityFramework();

You can check out the official documentation of miniprofiler(https://miniprofiler.com/dotnet/AspDotNetCore)

And if your server lives on a different domain from your Angular app, you may run into two CORS issues.

Firstly, you need to allow your app to request MiniProfiler results. For an ASP.NET Web API solution, that's one way of doing so (in the global.asax.cs file).

protected void Application_BeginRequest() 
{ 
    var context = HttpContext.Current; 
    if (HttpContext.Current.Request.Path.StartsWith("/mini-profiler-resources")) 
    { 
        var origin = context.Request.Headers.Get("Origin"); 
        if (origin != null) 
        { 
            context.Response.Headers.Add("Access-Control-Allow-Origin", origin); 
        } 
        if (context.Request.HttpMethod == "OPTIONS") 
        { 
            context.Response.StatusCode = 200; 
            context.Response.Headers.Add("Access-Control-Allow-Headers", "Content-Type"); 
            context.Response.Headers.Add("Access-Control-Allow-Methods", "OPTIONS, GET"); 
        } 
    } 
}

Secondly, your server needs to let your Angular app access the X-MiniProfiler-Ids headers. You may do that by adding an ActionFilter.

public class MiniProfilerCorsHeaderFilter : ActionFilterAttribute
{
    public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
    {
        actionExecutedContext.Response.Headers.Add("Access-Control-Expose-Headers", "X-MiniProfiler-Ids");
    }
}

or by adding in CORS.

public class MiniProfilerCorsHeaderFilter : ActionFilterAttribute
{
    app.UseCors(builder =>
                builder.WithOrigins("http://example.com")
                .AllowAnyMethod()
                .AllowAnyHeader()
                .WithExposedHeaders("x-miniprofiler-ids"));
}

Enable mini-profiler manually

If you set the enableGlobalMethod configuration to true, you may call the enableMiniProfiler from your browser's devtools console to enable MiniProfiler manually.

> enableMiniProfiler();
>
> MiniProfiler loaded.