Skip to content

Instantly share code, notes, and snippets.

View cristoni's full-sized avatar

Gabriele Cristoni cristoni

View GitHub Profile
touch tsconfig.json
yarn add --dev typescript @types/react @types/node
@cristoni
cristoni / _app.js
Created November 16, 2018 16:18
File _app.js per Nextjs com registrazione service worker
import App, { Container } from 'next/app'
export default class MyApp extends App {
static async getInitialProps({ Component, router, ctx }) {
let pageProps = {}
if (Component.getInitialProps) {
pageProps = await Component.getInitialProps(ctx)
}
@cristoni
cristoni / service-worker.js
Created November 15, 2018 07:56
Esempio di service worker con workbox per workbox-webpack-plugin
if (workbox) {
console.log(`Yay! Workbox is loaded 🎉`);
// workbox.setConfig({ debug: false });
// workbox.precaching.suppressWarnings();
workbox.precaching.precacheAndRoute(self.__precacheManifest, {});
workbox.routing.registerRoute(/^https?.*/, workbox.strategies.networkFirst(), 'GET');
} else {
console.log(`Boo! Workbox didn't load 😬`);
}
@cristoni
cristoni / next.config.js
Last active November 16, 2018 20:07
Esempio di nextjs config file con sass, compose e offline
const compose = require('next-compose');
const withSass = require('@zeit/next-sass');
const { InjectManifest } = require('workbox-webpack-plugin');
module.exports = compose([
[withSass],
{
webpack: config => {
const swOptions = {
@cristoni
cristoni / app.module.ts
Created November 10, 2018 11:37
Main module for NestJS application
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ConfigModule } from './config/config.module';
@Module({
imports: [ConfigModule],
controllers: [AppController],
providers: [AppService],
})
@cristoni
cristoni / config.module.ts
Created November 10, 2018 11:36
Config module for NestJS
import { Module } from '@nestjs/common';
import { ConfigService } from './config.service';
@Module({
providers: [
{
// Load the service as a provider
provide: ConfigService,
// Tells the service which file to load upon initialization
@cristoni
cristoni / config.service.ts
Created November 10, 2018 11:32
Config service for NestJS
import * as dotenv from 'dotenv';
import * as Joi from 'joi';
import * as fs from 'fs';
export interface EnvConfig {
[key: string]: string;
}
/**
* ConfigService is used the load, validate and inject our projects configuration