Skip to content

Instantly share code, notes, and snippets.

View riccardogiorato's full-sized avatar
🏠
Working from home

Riccardo Giorato riccardogiorato

🏠
Working from home
View GitHub Profile
Aurora V1 (EOL’ing) Aurora V2 Planetscale Neon
“No SSH”
Autoscaling ❌Up on certain tiers, down within limits
Pay based on usage ✅Compute, Storage, Network ✅Compute, Storage, Network ✅Compute, Storage, Reads, Writes ✅Compute, Storage
Resource usage scales to zero ✅*with slow cold starts
Cost scales to zero ❌$19/month minimum
import { NextRequest, NextResponse } from "next/server";
import { Redis } from "@upstash/redis";
export const config = {
runtime: "edge",
};
if (
!process.env.UPSTASH_REDIS_REST_URL ||
!process.env.UPSTASH_REDIS_REST_TOKEN
) {
@riccardogiorato
riccardogiorato / newsletter-sla.ts
Created January 26, 2023 16:11
api/newsletter-sla.ts inside your next.js project
import type { NextApiRequest, NextApiResponse } from "next";
import { Client } from "@upstash/qstash";
type ResponseEmailNewsletter =
| {
error: string;
}
| {
message: string;
};
@riccardogiorato
riccardogiorato / newsletter.ts
Created January 26, 2023 15:57
api/newsletter.ts inside your next.js project
// Full code here: https://github.com/riccardogiorato/qstash-with-nextjs
import type { NextApiRequest, NextApiResponse } from "next";
type ResponseEmailNewsletter =
| {
error: string;
}
| {
message: string;
};
- from: /me
to: https://github.com/ThewBear
status: 308 # Change status code ex. 301, 302, 307 (Default), 308
- from: /google/:q # Match exactly one ex. /google/recursion
to: https://google.com/search?q=:q
- from: /vercel/:slug* # Match zero or more ex. /vercel /vercel/docs /vercel/solutions/nextjs
to: https://vercel.com/:slug
- from: /twitter/:slug? # Match Zero or one ex. /twitter /twitter/thewdhanat
to: https://twitter.com/:slug
- from: /github/:slug+ # One or more ex. /github/ThewApp github/ThewApp/vercel-shorturl
// /api/reverse-proxy/[...all].ts
import { NextApiRequest, NextApiResponse } from "next/types";
import httpProxyMiddleware from "next-http-proxy-middleware";
export const config = {
api: {
externalResolver: true,
},
// STEPS to solve a problem:
// 1. define what are the input variables
// 2. what is the output format or the result
// 3. define what constants are in the problem?
// 3. (not always) Find the solution the real world if you had to give these instruction to a group of kids
// 4. Reverse engineer the ouput from input
// INPUT variables for the room size
// l = number, lenght of the room in m
// h = number, height of the room in m
/// <reference types="cypress-mailosaur" />
describe("Slack New Account Email", async function () {
Cypress.on("uncaught:exception", () => {
return false;
});
const testId = new Date().getTime();
const serverId = "SERVER_ID"; // Replace this ID with your actual Mailosaur Server ID
const testEmail = `slack-new-account${testId}@${serverId}.mailosaur.net`;
describe("Stripe Checkout", () => {
it("Stripe Checkout test mode works!", () => {
cy.request(
"https://checkout.stripe.dev/api/demo-session?country=us&billingPeriod=monthly&hasBgColor=false&hasBillingAndShipping=false&hasCoupons=false&hasFreeTrial=false&hasShippingRate=false&hasTaxes=false&mode=payment&wallet=googlePay&hasPolicies=false&billingType=flat"
).then((response) => {
expect(response.status).to.eq(200);
expect(response.body).to.have.property("url");
cy.visit(response.body.url);
cy.url().should("contains", "https://checkout.stripe.com/pay/");
const baseUrlTesla = "https://www.tesla.com/";
const url404test = "https://www.tesla.com/not-a-real-page";
it("404 'not found' response", () => {
cy.request({
url: url404test,
followRedirect: false,
failOnStatusCode: false,
}).then((resp) => {
expect(resp.status).to.eq(404);
expect(resp.redirectedToUrl).to.eq(undefined);