diff --git a/client/.angular-cli.json b/client/.angular-cli.json index dbea468..1d3d0d0 100755 --- a/client/.angular-cli.json +++ b/client/.angular-cli.json @@ -1,69 +1,63 @@ { - "$schema": "./node_modules/@angular/cli/lib/config/schema.json", - "project": { - "name": "pod-noms.web" - }, - "apps": [ - { - "root": "src", - "outDir": "dist", - "assets": [ - "assets", - "favicon.ico" - ], - "index": "index.html", - "main": "main.ts", - "polyfills": "polyfills.ts", - "test": "test.ts", - "tsconfig": "tsconfig.app.json", - "testTsconfig": "tsconfig.spec.json", - "prefix": "app", - "serviceWorker": true, - "styles": [ - "../node_modules/font-awesome/css/font-awesome.css", - "../node_modules/simple-line-icons/css/simple-line-icons.css", - "styles.css" - ], - "scripts": [ - "../node_modules/jquery/dist/jquery.js", - "../node_modules/tether/dist/js/tether.js", - "../node_modules/popper.js/dist/umd/popper.min.js", - "../node_modules/bootstrap/dist/js/bootstrap.js" - ], - "environmentSource": "environments/environment.ts", - "environments": { - "dev": "environments/environment.ts", - "prod": "environments/environment.prod.ts" - } - } - ], - "e2e": { - "protractor": { - "config": "./protractor.conf.js" - } - }, - "lint": [ - { - "project": "src/tsconfig.app.json" + "$schema": "./node_modules/@angular/cli/lib/config/schema.json", + "project": { + "name": "pod-noms.web" }, - { - "project": "src/tsconfig.spec.json" + "apps": [ + { + "root": "src", + "outDir": "dist", + "assets": ["assets", "favicon.ico"], + "index": "index.html", + "main": "main.ts", + "polyfills": "polyfills.ts", + "test": "test.ts", + "tsconfig": "tsconfig.app.json", + "testTsconfig": "tsconfig.spec.json", + "prefix": "app", + "serviceWorker": true, + "styles": [ + "../node_modules/font-awesome/css/font-awesome.css", + "../node_modules/simple-line-icons/css/simple-line-icons.css", + "styles.css" + ], + "scripts": [ + "../node_modules/jquery/dist/jquery.js", + "../node_modules/tether/dist/js/tether.js", + "../node_modules/popper.js/dist/umd/popper.min.js", + "../node_modules/bootstrap/dist/js/bootstrap.js" + ], + "environmentSource": "environments/environment.ts", + "environments": { + "dev": "environments/environment.ts", + "prod": "environments/environment.prod.ts" + } + } + ], + "e2e": { + "protractor": { + "config": "./protractor.conf.js" + } }, - { - "project": "e2e/tsconfig.e2e.json" - } - ], - "test": { - "karma": { - "config": "./karma.conf.js" - } - }, - "defaults": { - "styleExt": "css", - "component": { + "lint": [ + { + "project": "src/tsconfig.app.json" + }, + { + "project": "src/tsconfig.spec.json" + }, + { + "project": "e2e/tsconfig.e2e.json" + } + ], + "test": { + "karma": { + "config": "./karma.conf.js" + } }, - "serve": { - "host": "dev.podnoms.com" + "defaults": { + "styleExt": "css", + "component": {} + } - } } diff --git a/client/src/app/services/push-notifications.service.ts b/client/src/app/services/push-notifications.service.ts index 2012dbd..9078a55 100644 --- a/client/src/app/services/push-notifications.service.ts +++ b/client/src/app/services/push-notifications.service.ts @@ -43,10 +43,11 @@ export class PushNotificationsService { } subscribeToServerPush() { - console.log('PushNotificationsService', 'subscribeToServerPush'); + console.log('PushNotificationsService', 'subscribeToServerPush', this.vapidPublicKey); this._pushServiceWorker.requestSubscription({ serverPublicKey: this.vapidPublicKey }).then(pushSubscription => { + console.log('PushNotificationsService', 'subscribeToServerPush', pushSubscription); this._pushService.addSubscriber(pushSubscription) .subscribe(res => { console.log('PushNotificationsService', 'subscribeToServerPush', res); @@ -59,6 +60,7 @@ export class PushNotificationsService { } createNotification(subject: string, text: string) { + console.log('PushNotificationsService', 'createNotification', subject, text); if (this.isSupported()) { const options = { body: text, @@ -74,3 +76,4 @@ export class PushNotificationsService { } } } + diff --git a/client/src/app/services/push.service.ts b/client/src/app/services/push.service.ts index c5a727c..d4675c5 100644 --- a/client/src/app/services/push.service.ts +++ b/client/src/app/services/push.service.ts @@ -31,13 +31,8 @@ export class PushService { const url = `${this.API_URL}/webpush/subscribe`; console.log('[Push Service] Adding subscriber') - let body = { - action: 'subscribe', - subscription: subscription - } - return this.http - .post(url, body) + .post(url, subscription) .catch(this.handleError); } diff --git a/client/src/environments/environment.prod.ts b/client/src/environments/environment.prod.ts index 9c8a846..86a6b55 100755 --- a/client/src/environments/environment.prod.ts +++ b/client/src/environments/environment.prod.ts @@ -1,7 +1,7 @@ export const environment = { production: true, - API_HOST: 'https://localhost:5001', - // API_HOST: 'https://podnoms.com/api', + // API_HOST: 'https://api.podnoms.com', + API_HOST: 'https://dev2.podnoms.com:5001', SIGNALR_HOST: 'https://rt.podnoms.com/', AUTH0_REDIRECT_URL: 'https://podnoms.com/callback', BASE_URL: 'https://podnoms.com', diff --git a/client/src/ngsw-config.json b/client/src/ngsw-config.json index 1c7f472..3221e5b 100644 --- a/client/src/ngsw-config.json +++ b/client/src/ngsw-config.json @@ -1,27 +1,25 @@ { "index": "/index.html", - "assetGroups": [{ - "name": "app", - "installMode": "prefetch", - "resources": { - "files": [ - "/favicon.ico", - "/index.html" - ], - "versionedFiles": [ - "/*.bundle.css", - "/*.bundle.js", - "/*.chunk.js" - ] + "assetGroups": [ + { + "name": "app", + "installMode": "prefetch", + "resources": { + "files": ["/favicon.ico", "/index.html"], + "versionedFiles": [ + "/*.bundle.css", + "/*.bundle.js", + "/*.chunk.js" + ] + } + }, + { + "name": "assets", + "installMode": "lazy", + "updateMode": "prefetch", + "resources": { + "files": ["/assets/**"] + } } - }, { - "name": "assets", - "installMode": "lazy", - "updateMode": "prefetch", - "resources": { - "files": [ - "/assets/**" - ] - } - }] + ] } diff --git a/server/Controllers/WebPushController.cs b/server/Controllers/WebPushController.cs index 7f2c5c6..a4cc8d7 100644 --- a/server/Controllers/WebPushController.cs +++ b/server/Controllers/WebPushController.cs @@ -7,7 +7,7 @@ using PodNoms.Api.Services.Push.Models; namespace PodNoms.Api.Controllers { - [Authorize] + // [Authorize] [Route("[controller]")] public class WebPushController : Controller { private readonly IPushSubscriptionStore _subscriptionStore; @@ -17,7 +17,7 @@ namespace PodNoms.Api.Controllers { this._subscriptionStore = subscriptionStore; this._notificationService = notificationService; } - + [HttpPost("subscribe")] public async Task StoreSubscription([FromBody]PushSubscription subscription) { await _subscriptionStore.StoreSubscriptionAsync(subscription); @@ -25,7 +25,7 @@ namespace PodNoms.Api.Controllers { } // POST push-notifications-api/notifications - [HttpPost("notifications")] + [HttpPost("message")] public async Task SendNotification([FromBody]PushMessageViewModel message) { PushMessage pushMessage = new PushMessage(message.Notification) { Topic = message.Topic, diff --git a/server/PodNoms.Api.csproj b/server/PodNoms.Api.csproj index 2459406..871e7cb 100755 --- a/server/PodNoms.Api.csproj +++ b/server/PodNoms.Api.csproj @@ -2,6 +2,7 @@ netcoreapp2.1 aspnet-PodNoms.Api-1E27B6DE-BA4B-4F75-BBF8-CA34FB4D260A + latest @@ -12,7 +13,7 @@ - + @@ -20,6 +21,7 @@ + diff --git a/server/Program.cs b/server/Program.cs index 5876bed..93861c8 100755 --- a/server/Program.cs +++ b/server/Program.cs @@ -11,6 +11,9 @@ using Microsoft.Extensions.Logging; namespace PodNoms.Api { public class Program { + static bool isDevelopment = + Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == EnvironmentName.Development; + public static void Main (string[] args) { CreateWebHostBuilder (args).Build ().Run (); } @@ -19,9 +22,11 @@ namespace PodNoms.Api { .UseStartup () .UseKestrel(options => { options.Listen(IPAddress.Any, 5000); - options.Listen(IPAddress.Any, 5001, listenOptions => { - listenOptions.UseHttps("certs/dev.pfx", "secret"); - }); - }); + if (isDevelopment){ + options.Listen(IPAddress.Any, 5001, listenOptions => { + listenOptions.UseHttps("certs/dev2.podnoms.com.pfx", "secret"); + }); + } + }); } } diff --git a/server/Startup.cs b/server/Startup.cs index ac962ff..9acef53 100755 --- a/server/Startup.cs +++ b/server/Startup.cs @@ -40,6 +40,7 @@ using PodNoms.Api.Services.Push.Extensions; using Swashbuckle.AspNetCore.Swagger; using PodNoms.Api.Services.Push.Formatters; +using Microsoft.AspNetCore.HttpOverrides; namespace PodNoms.Api { public class Startup { @@ -69,6 +70,15 @@ namespace PodNoms.Api { services.AddHangfire(config => { config.UseMemoryStorage(); }); + + services.AddPushSubscriptionStore(Configuration) + .AddPushNotificationService(Configuration) + .AddMvc(options => { + options.InputFormatters.Add(new TextPlainInputFormatter()); + }) + .AddJsonOptions(options => { + options.SerializerSettings.Converters.Add(new StringEnumConverter()); + }); } public void ConfigureServices(IServiceCollection services) { Console.WriteLine($"Configuring services: {Configuration.ToString()}"); @@ -199,7 +209,7 @@ namespace PodNoms.Api { Console.WriteLine("Successfully migrated"); // app.UseHsts(); - app.UseHttpsRedirection(); + // app.UseHttpsRedirection(); app.UseStaticFiles(); GlobalConfiguration.Configuration.UseActivator(new ServiceProviderActivator(serviceProvider)); @@ -211,6 +221,11 @@ namespace PodNoms.Api { }); } + app.UseForwardedHeaders(new ForwardedHeadersOptions { + ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto + }); + app.UseAuthentication(); + app.UseCors("AllowAllOrigins"); app.UseSignalR(routes => { @@ -225,6 +240,8 @@ namespace PodNoms.Api { c.RoutePrefix = ""; }); + app.UseSqlitePushSubscriptionStore(); + app.UseMvc(routes => { routes.MapRoute( name: "default",