Skip to content

Instantly share code, notes, and snippets.

Raymon S raymonschouwenaar

View GitHub Profile
View async-function-call-api.ts
async function callApi() {
const response = await fetch("...");
const greeting = await response.text();
console.log(greeting);
}
callApi()
View lazyloading.html
<img src="https://source.unsplash.com/random" loading="lazy" />
<iframe
src="https://raymonschouwenaar.nl"
width="100%"
height="500px"
loading="lazy"
></iframe>
View app.component.ts
import { Component, OnInit } from '@angular/core'
import { HttpClient } from '@angular/common/http'
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit {
title = 'ng-faunadb-netlify-serverless-functions'
View app.module.ts
import { BrowserModule } from '@angular/platform-browser'
import { NgModule } from '@angular/core'
import { AppRoutingModule } from './app-routing.module'
import { AppComponent } from './app.component'
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'
import { HttpClientModule } from '@angular/common/http'
@NgModule({
declarations: [AppComponent],
View products-response.json
[
{
"ref": {
"@ref": {
"id": "266790280843231752",
"collection": {
"@ref": {
"id": "products",
"collection": {
"@ref": {
View products.js
import { ProductService } from '../lib/product-service.js'
import { client, headers } from '../lib/config.js'
const service = new ProductService({ client })
exports.handler = async (event, context) => {
console.log('Function `products` invoked')
if (event.httpMethod !== 'GET') {
return { statusCode: 405, headers, body: 'Method Not Allowed' }
View product-service.js
import faunadb from 'faunadb'
const q = faunadb.query
export class ProductService {
constructor(data) {
this.client = data.client
}
async getProducts() {
return new Promise((resolve, reject) => {
View config.js
import faunadb from 'faunadb'
require('dotenv').config()
const headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Content-Type',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE',
}
const client = new faunadb.Client({
View hello.js
export async function handler(event, context) {
return {
statusCode: 200, // response status code
body: 'Hello, World', // response body
}
}
View package.json
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"fn:serve": "netlify-lambda serve functions",
"fn:build": "netlify-lambda build functions"
},
You can’t perform that action at this time.