Skip to content

Instantly share code, notes, and snippets.

@kiliman
kiliman / pm2.config.js
Last active November 23, 2021 00:08
PM2 config to handle Remix/Express/TailwindCSS + rsync to reduce duplicate reloads
module.exports = {
apps: [
{
name: "Express",
script: "server/index.js",
watch: ["server/index.js"],
watch_options: {
followSymlinks: false,
},
env: {
@kiliman
kiliman / react-router+6.0.2.patch
Created December 7, 2021 23:20
Patch for react-router to fix no matching paths with leading . (e.g. /.well-known/acme-challenge/abc123)
diff --git a/node_modules/react-router/umd/react-router.development.js b/node_modules/react-router/umd/react-router.development.js
index bfb1dc6..6aa8ba5 100644
--- a/node_modules/react-router/umd/react-router.development.js
+++ b/node_modules/react-router/umd/react-router.development.js
@@ -820,7 +820,9 @@
: // Otherwise, at least match a word boundary. This restricts parent
// routes to matching only their own words and nothing more, e.g. parent
// route "/home" should not match "/home2".
- "(?:\\b|$)";
+ // PATCH: return "" instead of "\\b" because it fails to match leading .
@kiliman
kiliman / @remix-run+server-runtime+1.0.6.patch
Created December 8, 2021 16:41
PATCH to add request and context to Remix CatchBoundary
diff --git a/node_modules/@remix-run/server-runtime/server.js b/node_modules/@remix-run/server-runtime/server.js
index eef3403..d483581 100644
--- a/node_modules/@remix-run/server-runtime/server.js
+++ b/node_modules/@remix-run/server-runtime/server.js
@@ -226,7 +226,9 @@ async function handleDocumentRequest(request, loadContext, build, platform, rout
componentDidCatchEmulator.catch = {
status: requestState === "no-match" ? 404 : 405,
statusText: requestState === "no-match" ? "Not Found" : "Method Not Allowed",
- data: null
+ data: null,
@kiliman
kiliman / globals.js
Created January 5, 2022 19:42
remix-fastify adapter
'use strict';
var node = require('@remix-run/node');
node.installGlobals();
@kiliman
kiliman / server-index.js
Created January 8, 2022 16:07
Remix Express handler that checks for auth cookie/token and return 401 if missing on non-anonymous routes
function handleRequest(req, res, next) {
let build = require('./build')
if (MODE !== 'production') {
purgeRequireCache()
}
if (requireAuthentication(req)) {
return unauthenticated(req, res)
}
return createRequestHandler({
build,
@kiliman
kiliman / LiveReload.tsx
Last active January 19, 2022 15:44
Remix Run and Tailwind CSS config with jit support
export default function () {
return process.env.NODE_ENV === 'development' ? (
<script src="http://localhost:35729/livereload.js?snipver=1"></script>
) : null
}
@kiliman
kiliman / main.js
Last active January 25, 2022 00:30
Remix Electron to add menus and navigate to routes
// @ts-check
const electron = require("electron");
const { app, BrowserWindow, dialog, Menu } = electron;
const { startServer } = require("./server");
let win;
let server;
async function main() {
await app.whenReady();
@kiliman
kiliman / @remix-run+dev+1.2.3.patch
Last active March 3, 2022 22:18
Patch to enable breakpoint debugging in Remix route modules
diff --git a/node_modules/@remix-run/dev/compiler.js b/node_modules/@remix-run/dev/compiler.js
index 9bbf9b1..783ccad 100644
--- a/node_modules/@remix-run/dev/compiler.js
+++ b/node_modules/@remix-run/dev/compiler.js
@@ -371,7 +371,7 @@ async function createServerBuild(config, options, assetsManifestPromiseRef) {
bundle: true,
logLevel: "silent",
incremental: options.incremental,
- sourcemap: options.sourcemap ? "inline" : false,
+ sourcemap: options.sourcemap,
@ECHO off
GOTO start
:find_dp0
SET dp0=%~dp0
EXIT /b
:start
SETLOCAL
CALL :find_dp0
IF EXIST "%dp0%\node.exe" (
@kiliman
kiliman / ErrorBoundary.tsx
Created February 25, 2022 19:03
ErrorBoundary that displays the actual source file and highlights the line
export const ErrorBoundary = ({ error }: any) => {
const [source, setSource] = useState('')
const lines = error.stack.split('\n')
const match = lines[1].match(/(?<path>.+):(?<line>\d+):(?<column>\d+)/)
let path = ''
let linenumber = 0
let column = 0
if (match) {
path = match.groups.path
linenumber = Number(match.groups.line)