abp icon indicating copy to clipboard operation
abp copied to clipboard

SPA with Angular

Open crashsol opened this issue 7 years ago • 7 comments

I want use abp vnext with Angular,add officical identity、permissionManager、audit modules,but i don't know how to work, could you give a sample step by step like Acme.BookStore MVC Sample

crashsol avatar Mar 04 '19 05:03 crashsol

Will create a SPA startup template. However, I can not give a step by step sample, that is not trival.

hikalkan avatar Mar 04 '19 16:03 hikalkan

hi,@hikalkan do you have plan to create a spa startup template for angular ? (just a sample ,no step by step document required) ?

ChangYinShung avatar Jul 04 '20 05:07 ChangYinShung

@ChangYinShung we have already created Angular startup template (see https://docs.abp.io/en/abp/latest/Getting-Started?UI=NG&DB=EF&Tiered=No). Do you mean something else?

hikalkan avatar Jul 05 '20 20:07 hikalkan

@hikalkan when i follow this tutorial(https://docs.abp.io/en/abp/latest/Getting-Started?UI=NG&DB=EF&Tiered=No): When deploy it to IIS, i need to create two port on iis(one for angular,other for backend) .

In some case, i need deploy angular and backend in same port(80).

1.I install nuget Microsoft.AspNetCore.SpaServices.Extensions on .HttpApi.Host and add UseSpa

            app.UseAuditing();
            app.UseConfiguredEndpoints();
            app.UseSpaStaticFiles();
            app.UseSpa(spa =>
            {
                // To learn more about options for serving an Angular SPA from ASP.NET Core,
                // see https://go.microsoft.com/fwlink/?linkid=864501
                spa.Options.SourcePath = "wwwroot/dist";
            });

2.Run build angular and move angular dist folder to wwwroot folder 3.create an site and deploy to iis.

What is best practice for deploy an SPA application(angular) ?

ChangYinShung avatar Jul 06 '20 04:07 ChangYinShung

For the ABP Commercial demo, we are using the same port for Angular & Backend. But I am not sure if we've used the Microsoft.AspNetCore.SpaServices.Extensions. @ismcagdas?

We had created a "One solution (include the client side project into the server side solution instead of separate solutions)" for the ASP.NET Boilerplate download before. We may consider to add a similar thing here. Is that what do you want? If so, can you create a new issue please?

hikalkan avatar Jul 26 '20 14:07 hikalkan

We don't use Microsoft.AspNetCore.SpaServices.Extensions. In order to host both apps on the same port, we include a custom middleware for ASP.NET Core project which redirects all not found URLs to Angular project's index.html. Something like this;

app.Use(async (ctx, next) =>
{
	if (ShouldRedirectToAngularApp(ctx))
	{
		ctx.Request.Path = "/index.html";
		await next();
	}
	else
	{
		await next();

		if (ShouldRedirectToAngularApp(ctx))
		{
			ctx.Request.Path = "/index.html";
			await next();
		}
	}
});
			
			
private static bool ShouldRedirectToAngularApp(HttpContext ctx)
{
	return ctx.Response.StatusCode == 404
		   && !Path.HasExtension(ctx.Request.Path.Value)
		   && !ctx.Request.Path.Value.StartsWith("/api/services", StringComparison.InvariantCultureIgnoreCase);
}			

ismcagdas avatar Jul 27 '20 07:07 ismcagdas

We had created a "One solution (include the client side project into the server side solution instead of separate solutions)" for the ASP.NET Boilerplate download before. We may consider to add a similar thing here. Is that what do you want? If so, can you create a new issue please?

yes, i will create new issue thanks.

ChangYinShung avatar Sep 28 '20 02:09 ChangYinShung