<?php declare(strict_types = 1); | |
namespace App\Tests; | |
use Closure; | |
use PHPUnit\Framework\Assert; | |
use ReflectionClass; | |
use ReflectionFiber; | |
use ReflectionFunction; | |
use ReflectionGenerator; |
script:pre-request { | |
const { login } = require('./utils') | |
await login(req) | |
} | |
# Alpine image is smaller but Prisma is broken on M1 https://github.com/prisma/prisma/issues/8478 | |
# FROM node:18-alpine AS builder | |
# RUN apk update | |
# RUN apk add --no-cache openssl | |
FROM node:18-slim AS runner | |
RUN apt-get update \ | |
&& apt-get install -y openssl | |
ENV NODE_ENV production | |
ENV NEXT_TELEMETRY_DISABLED 1 |
Made this example to show how to use Next.js router for a 100% SPA (no JS server) app.
You use Next.js router like normally, but don't define getStaticProps
and such. Instead you do client-only fetching with swr
, react-query
, or similar methods.
You can generate HTML fallback for the page if there's something meaningful to show before you "know" the params. (Remember, HTML is static, so it can't respond to dynamic query. But it can be different per route.)
Don't like Next? Here's how to do the same in Gatsby.
// Regular expression patterns for testing content-type response headers. | |
var RE_CONTENT_TYPE_JSON = new RegExp( "^application/(x-)?json", "i" ); | |
var RE_CONTENT_TYPE_TEXT = new RegExp( "^text/", "i" ); | |
// Static strings. | |
var UNEXPECTED_ERROR_MESSAGE = "An unexpected error occurred while processing your request."; | |
export class ApiClient { | |
/** | |
* I initialize the API client. |
import { captureException, flush } from '@sentry/nextjs'; | |
import NextErrorComponent from 'next/error'; | |
import type { ErrorProps } from 'next/error'; | |
import type { NextPage } from 'next'; | |
interface AppErrorProps extends ErrorProps { | |
err?: Error; | |
hasGetInitialPropsRun?: boolean; | |
} |
/* | |
* MIT License | |
* | |
* Copyright (c) 2023-2024 Fabio Lima | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy | |
* of this software and associated documentation files (the "Software"), to deal | |
* in the Software without restriction, including without limitation the rights | |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
* copies of the Software, and to permit persons to whom the Software is |
⚠️ Note 2023-01-21
Some things have changed since I originally wrote this in 2016. I have updated a few minor details, and the advice is still broadly the same, but there are some new Cloudflare features you can (and should) take advantage of. In particular, pay attention to Trevor Stevens' comment here from 22 January 2022, and Matt Stenson's useful caching advice. In addition, Backblaze, with whom Cloudflare are a Bandwidth Alliance partner, have published their own guide detailing how to use Cloudflare's Web Workers to cache content from B2 private buckets. That is worth reading,