Skip to content

Instantly share code, notes, and snippets.

const triggerPushMsg = function(subscription, dataToSend) {
let _subscription = subscription.subscriber;
let pushSubscription = JSON.parse(_subscription);
let buildPushSubscription = {
endpoint: pushSubscription.endpoint,
keys: pushSubscription.keys
};
return webpush.sendNotification(buildPushSubscription, dataToSend)
.catch((err) => {
if (err.statusCode === 410) {
exports.notification = (req, res, next) => {
const notificationPayload = {
notification: {
title: 'Blogial new post',
body: req.body.title,
icon: 'assets/icons/icon-512x512.png'
}
};
Subscription.find()
.then(subscriptions => {
Questo e app-routing
const routes: Routes = [
{ path: '', loadChildren: './features/blog/blog.module#BlogModule', data: { preload: false , animation: {page: 'home'}} },
{ path: 'admin', loadChildren: './features/admin/admin.module#AdminModule', data: { preload: false, animation: {page: 'dashboard'} } },
{ path: 'auth', loadChildren: './features/authentication/authentication.module#AuthenticationModule', data: { preload: false, animation: {page: 'login'} } },
{ path: '**', redirectTo: '', pathMatch: 'full' }
];
@NgModule({
'use strict';
const multer = require('multer');
const MIME_TYPE_MAP = {
'image/png': 'png',
'image/jpeg': 'jpg',
'image/jpg': 'jpg'
};
const storage = multer.diskStorage({
import { Observable, BehaviorSubject } from 'rxjs';
import { pluck, distinctUntilChanged } from 'rxjs/operators';
import { User } from './auth/shared/services/auth/auth.service';
import { Meal } from './health/shared/services/meals/meals.service';
export interface State {
user: User,
meals: Meal[],
export function clearState(reducer: ActionReducer<State>): ActionReducer<State> {
return function(state: State, action: Action): State {
console.log('action',action.type);
console.log('state',state);
if (action.type === '[Auth] Logout') {
console.log('BINGO');
state = undefined;
}
return reducer(state, action);
};
export class PwaService {
promptEvent: ServiceWorkerEvent;
constructor(private swUpdate: SwUpdate, platform: PlatformService) {
if(platform.isBrowser() && environment.production){
console.log('hello browser');
swUpdate.available.subscribe(event => {
console.log('current version is', event.current);
console.log('available version is', event.available);
if (window.confirm('Want to update?')) {
swUpdate.activateUpdate().then(() => {
export const customStorage: Storage = {
length: 0,
clear: function(): void {
if (window && window.localStorage) {
window.localStorage.clear();
this.length = window.localStorage.length;
}
},
getItem: function(key: string): string | null {
try {
// VECCHIO
.pipe(
tap((event: HttpEvent<any>) => {
if (event instanceof HttpResponse) {
}
}, (err: any) => {
if (err instanceof HttpErrorResponse) {
// do something
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return this.store.select(fromStore.getToken)
.pipe(
take(1),
switchMap((token: AuthenticationToken) => {
console.log('token',token);
if (token) {
const clonedRequest = request.clone({
setHeaders: {
Authorization: `Bearer ${token.token}`