Skip to content

Commit

Permalink
templates: use TS server file
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDeBoey committed Mar 23, 2023
1 parent 72c22b3 commit 8922f83
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 19 deletions.
2 changes: 1 addition & 1 deletion templates/arc/remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module.exports = {
ignoredRouteFiles: ["**/.*"],
publicPath: "/_static/build/",
server: "./server.js",
server: "./server.ts",
serverBuildPath: "server/index.js",
// appDirectory: "app",
// assetsBuildDirectory: "public/build",
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion templates/cloudflare-pages/remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module.exports = {
devServerBroadcastDelay: 1000,
ignoredRouteFiles: ["**/.*"],
server: "./server.js",
server: "./server.ts",
serverBuildPath: "functions/[[path]].js",
serverConditions: ["worker"],
serverDependenciesToBundle: "all",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ const handleRequest = createPagesFunctionHandler({
getLoadContext: (context) => context.env,
});

export function onRequest(context) {
export function onRequest(context: EventContext<any, any, any>) {
return handleRequest(context);
}
1 change: 1 addition & 0 deletions templates/cloudflare-pages/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"include": ["remix.env.d.ts", "**/*.ts", "**/*.tsx"],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2019"],
"types": ["@cloudflare/workers-types"],
"isolatedModules": true,
"esModuleInterop": true,
"jsx": "react-jsx",
Expand Down
2 changes: 1 addition & 1 deletion templates/cloudflare-workers/remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module.exports = {
devServerBroadcastDelay: 1000,
ignoredRouteFiles: ["**/.*"],
server: "./server.js",
server: "./server.ts",
serverConditions: ["worker"],
serverDependenciesToBundle: "all",
serverMainFields: ["browser", "module", "main"],
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion templates/netlify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"typecheck": "tsc"
},
"dependencies": {
"@netlify/functions": "^1.3.0",
"@netlify/functions": "^1.4.0",
"@remix-run/netlify": "*",
"@remix-run/node": "*",
"@remix-run/react": "*",
Expand Down
2 changes: 1 addition & 1 deletion templates/netlify/remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
ignoredRouteFiles: ["**/.*"],
server:
process.env.NETLIFY || process.env.NETLIFY_LOCAL
? "./server.js"
? "./server.ts"
: undefined,
serverBuildPath: ".netlify/functions-internal/server.js",
// appDirectory: "app",
Expand Down
18 changes: 6 additions & 12 deletions templates/netlify/server.js → templates/netlify/server.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import type { HandlerEvent, HandlerContext } from "@netlify/functions";
import { createRequestHandler } from "@remix-run/netlify";
import * as build from "@remix-run/dev/server-build";

/*
* Returns a context object with at most 3 keys:
* - `netlifyGraphToken`: raw authentication token to use with Netlify Graph
* Returns a context object with at most 2 keys:
* - `clientNetlifyGraphAccessToken`: For use with JWTs generated by
* `netlify-graph-auth`.
* - `netlifyGraphSignature`: a signature for subscription events. Will be
* present if a secret is set.
*/
function getLoadContext(event, context) {
function getLoadContext(event: HandlerEvent, context: HandlerContext) {
let rawAuthorizationString;
let netlifyGraphToken;

if (event.authlifyToken != null) {
netlifyGraphToken = event.authlifyToken;
}

const authHeader = event.headers["authorization"];
const graphSignatureHeader = event.headers["x-netlify-graph-signature"];
Expand All @@ -26,14 +21,13 @@ function getLoadContext(event, context) {

const loadContext = {
clientNetlifyGraphAccessToken: rawAuthorizationString,
netlifyGraphToken: netlifyGraphToken,
netlifyGraphSignature: graphSignatureHeader,
};

// Remove keys with undefined values
Object.keys(loadContext).forEach((key) => {
if (loadContext[key] == null) {
delete loadContext[key];
Object.entries(loadContext).forEach(([key, value]) => {
if (value == null) {
delete loadContext[key as keyof typeof loadContext];
}
});

Expand Down
2 changes: 1 addition & 1 deletion templates/vercel/remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
// When running locally in development mode, we use the built-in remix
// server. This does not understand the vercel lambda module format,
// so we default back to the standard build output.
server: process.env.NODE_ENV === "development" ? undefined : "./server.js",
server: process.env.NODE_ENV === "development" ? undefined : "./server.ts",
serverBuildPath: "api/index.js",
// appDirectory: "app",
// assetsBuildDirectory: "public/build",
Expand Down
File renamed without changes.

0 comments on commit 8922f83

Please sign in to comment.