This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
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 furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all copies or | |
substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING | |
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// middleware.ts | |
import { NextResponse } from "next/server"; | |
import type { NextRequest } from "next/server"; | |
// This function can be marked `async` if using `await` inside | |
export function middleware(request: NextRequest) { | |
const url = request.nextUrl; | |
url.pathname = "/api/sitemap"; | |
return NextResponse.rewrite(url); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function fetchWordPressRedirects() { | |
if(!process.env.WORDPRESS_USERNAME | |
|| !process.env.WORDPRESS_PASSWORD | |
|| !process.env.REDIRECTION_API_ENDPOINT) { | |
return []; | |
} | |
const base64UsernamePasswordToken = Buffer.from( | |
process.env.WORDPRESS_USERNAME + ':' + process.env.WORDPRESS_PASSWORD | |
).toString('base64'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NextRequest, NextResponse } from "next/server"; | |
// eslint-disable-next-line import/prefer-default-export | |
export function middleware(req: NextRequest) { | |
const basicAuth = req.headers.get("authorization"); | |
// if the SITE_USERNAME and SITE_PASSWORD env values exist | |
// then we will require authentication for all requests | |
if (process.env.SITE_USERNAME && process.env.SITE_PASSWORD) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NextRequest, NextResponse } from "next/server"; | |
export function middleware(req: NextRequest) { | |
// PRIMARY_DOMAIN should be a full URL including protocol, e.g. https://www.google.com | |
const hasEnvVariable = !!process.env.PRIMARY_DOMAIN; | |
const isDevelopment = process.env.NODE_ENV === "development"; | |
if (!hasEnvVariable) { | |
!isDevelopment && | |
console.error( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Replacing domain for rest api requests from Gutenberg editor if youre using | |
* WP headless and WP_SITEURL & WP_HOME are not the same domain | |
* (has nothing to do with yoast) | |
*/ | |
add_filter('rest_url', function($url) { | |
$url = str_replace(home_url(), site_url(), $url); | |
return $url; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { createServer } = require('http'); | |
const { parse } = require('url'); | |
const next = require('next'); | |
const dev = process.env.NODE_ENV !== 'production'; | |
const app = next({ dev }); | |
const handle = app.getRequestHandler(); | |
const port = process.env.APP_PORT || 8080; | |
app.prepare().then(() => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { GetServerSidePropsContext } from "next"; | |
const defaultWpUrl = 'https://example.wpengine.com'; | |
const localHost = 'localhost:3000'; | |
const prodHost = 'example.com'; | |
export default function Sitemap () {}; | |
export const getServerSideProps = async (context: GetServerSidePropsContext) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<h1>Frameworks</h1> | |
<ul> | |
<li repeat.for="framework of state.frameworks">${framework}</li> | |
</ul> | |
</template> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
NewerOlder