Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: build for netlify edge #72

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ module.exports = {
"import/order": ["error", { alphabetize: { order: "asc" } }],
"sort-imports": ["error", { ignoreDeclarationSort: true }],
},
ignorePatterns: [".cache", "build", "node_modules", "coverage"],
ignorePatterns: [".cache", "build", "node_modules", "coverage", ".netlify"],
};
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/node_modules
/build
/.cache
/.netlify
/.env.staging.sh
/.env.production.sh
/coverage
4 changes: 4 additions & 0 deletions .netlify/edge-functions/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"functions": [{ "function": "index", "path": "/*" }],
"version": 1
}
94 changes: 94 additions & 0 deletions .patch/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .patch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
},
"dependencies": {
"@remix-run/dev": "^1.4.0",
"@remix-run/serve": "^1.4.0"
"@remix-run/serve": "^1.4.0",
"knex": "^1.0.4"
},
"devDependencies": {
"patch-package": "^6.4.7"
Expand Down
22 changes: 21 additions & 1 deletion .patch/patches/@remix-run+dev+1.4.1.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/node_modules/@remix-run/dev/compiler.js b/node_modules/@remix-run/dev/compiler.js
index 0de2694..91caea0 100644
index 0de2694..e8adbd8 100644
--- a/node_modules/@remix-run/dev/compiler.js
+++ b/node_modules/@remix-run/dev/compiler.js
@@ -331,7 +331,7 @@ async function createBrowserBuild(config, options) {
Expand All @@ -11,3 +11,23 @@ index 0de2694..91caea0 100644
metafile: true,
incremental: options.incremental,
mainFields: ["browser", "module", "main"],
@@ -375,6 +375,7 @@ function createServerBuild(config, options, assetsManifestPromiseRef) {
absWorkingDir: config.rootDirectory,
stdin,
entryPoints,
+ external: ["mysql"],
outfile: config.serverBuildPath,
write: false,
conditions: isCloudflareRuntime ? ["worker"] : undefined,
diff --git a/node_modules/@remix-run/dev/compiler/plugins/serverBareModulesPlugin.js b/node_modules/@remix-run/dev/compiler/plugins/serverBareModulesPlugin.js
index dede8a5..1cbcbe4 100644
--- a/node_modules/@remix-run/dev/compiler/plugins/serverBareModulesPlugin.js
+++ b/node_modules/@remix-run/dev/compiler/plugins/serverBareModulesPlugin.js
@@ -82,6 +82,7 @@ function serverBareModulesPlugin(remixConfig, dependencies, onWarning) {
// Always bundle everything for cloudflare.
case "cloudflare-pages":
case "cloudflare-workers":
+ case "deno":
return undefined;
}

28 changes: 28 additions & 0 deletions .patch/patches/knex+1.0.7.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
diff --git a/node_modules/knex/lib/knex-builder/make-knex.js b/node_modules/knex/lib/knex-builder/make-knex.js
index 55f9acd..51be552 100644
--- a/node_modules/knex/lib/knex-builder/make-knex.js
+++ b/node_modules/knex/lib/knex-builder/make-knex.js
@@ -1,7 +1,5 @@
const { EventEmitter } = require('events');

-const { Migrator } = require('../migrations/migrate/Migrator');
-const Seeder = require('../migrations/seed/Seeder');
const FunctionHelper = require('./FunctionHelper');
const QueryInterface = require('../query/method-constants');
const merge = require('lodash/merge');
@@ -47,6 +45,7 @@ const KNEX_PROPERTY_DEFINITIONS = {

migrate: {
get() {
+ const { Migrator } = require('../migrations/migrate/Migrator');
return new Migrator(this);
},
configurable: true,
@@ -54,6 +53,7 @@ const KNEX_PROPERTY_DEFINITIONS = {

seed: {
get() {
+ const Seeder = require('../migrations/seed/Seeder');
return new Seeder(this);
},
configurable: true,
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/misc/demo/*.yml
/misc/ytsub-v2/data-v2.json
/coverage
/.netlify/edge-functions/index.js
6 changes: 5 additions & 1 deletion app/misc/cli.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import * as assert from "assert";
import * as childProcess from "child_process";
import { promisify } from "util";
import { installGlobals } from "@remix-run/node";
import { cac } from "cac";
import { range, zip } from "lodash";
import { z } from "zod";
import { client } from "../db/client.server";
import { Q, filterNewVideo, insertVideoAndCaptionEntries } from "../db/models";
import { createUserCookie, register, verifySignin } from "../utils/auth";
import { exec, streamToString } from "../utils/node.server";
import { streamToString } from "../utils/node.server";
import { NewVideo, fetchCaptionEntries } from "../utils/youtube";

const exec = promisify(childProcess.exec);

const cli = cac("cli").help();

cli
Expand Down
4 changes: 3 additions & 1 deletion app/misc/env.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const env = {
APP_SESSION_SECRET: process.env.APP_SESSION_SECRET ?? "__secret__",
// APP_SESSION_SECRET: process.env.APP_SESSION_SECRET ?? "__secret__",
// @ts-ignore
APP_SESSION_SECRET: Deno.env.get("APP_SESSION_SECRET") ?? "__secret__",
};
31 changes: 31 additions & 0 deletions app/misc/netlify-edge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as build from "@remix-run/dev/server-build";
import { createRequestHandler as createRemixRequestHandler } from "@remix-run/server-runtime";

// cf. https://github.com/remix-run/remix/blob/fd9fa7f4b5abaa6a0c8204c66b92033815ba7d0e/packages/remix-netlify-edge/server.ts

// e.g. `context.next`
interface NetlifyEdgeContext {}

async function netlifyEdgeHandler(
request: Request,
_context: NetlifyEdgeContext
) {
const url = new URL(request.url);
// Hard-code root assets for CDN delegation
if (
url.pathname.startsWith("/build") ||
url.pathname.startsWith("/ui-dev") ||
url.pathname.startsWith("/_copy") ||
url.pathname.startsWith("/service-worker.js")
) {
return;
}
// {
// const res = { url: request.url, pathname: url.pathname };
// return new Response(JSON.stringify(res, null, 2));
// }
const remixHandler = createRemixRequestHandler(build);
return await remixHandler(request);
}

export default netlifyEdgeHandler;
Loading