Skip to content

Commit

Permalink
Merge branch 'azure-functions-host' of https://github.com/aaronpowell…
Browse files Browse the repository at this point in the history
…/remix into azure-functions-host
  • Loading branch information
aaronpowell committed Mar 29, 2022
2 parents e4583b2 + b2d6270 commit 215749b
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 69 deletions.
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
- matthew-burfield
- Matthew-Mallimo
- MatthewAlbrecht
- matt-l-w
- mattmazzola
- mattstobbs
- mbarto
Expand Down
116 changes: 56 additions & 60 deletions fixtures/gists-app/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,70 @@ const express = require("express");
const morgan = require("morgan");
const compression = require("compression");
const { createRequestHandler } = require("@remix-run/express");
const getPort = require("get-port");

getPort({ port: process.env.PORT || 3000 }).then((port) => {
if (process.env.NODE_ENV === "test") {
class MockConsole {
assert() {}
clear() {}
count() {}
countReset() {}
debug() {}
dir() {}
dirxml() {}
error() {}
group() {}
groupCollapsed() {}
groupEnd() {}
info() {}
log() {}
table() {}
time() {}
timeEnd() {}
timeLog() {}
timeStamp() {}
trace() {}
warn() {}
}
global.console = new MockConsole();
const port = process.env.PORT || 3000;

if (process.env.NODE_ENV === "test") {
class MockConsole {
assert() {}
clear() {}
count() {}
countReset() {}
debug() {}
dir() {}
dirxml() {}
error() {}
group() {}
groupCollapsed() {}
groupEnd() {}
info() {}
log() {}
table() {}
time() {}
timeEnd() {}
timeLog() {}
timeStamp() {}
trace() {}
warn() {}
}
global.console = new MockConsole();
}

let app = express();
let app = express();

app.use(compression());
app.use(compression());

app.use(
express.static("public", {
// maxAge: process.env.NODE_ENV === "production" ? "1y" : undefined
maxAge: "1y",
})
);
app.use(
express.static("public", {
// maxAge: process.env.NODE_ENV === "production" ? "1y" : undefined
maxAge: "1y",
})
);

app.get("/fails.css", (req, res) => {
res.status(500).send("Boom! No CSS here!");
});
app.get("/fails.css", (req, res) => {
res.status(500).send("Boom! No CSS here!");
});

// server-side redirect
app.get("/user-gists/:username", (req, res) => {
res.redirect(301, `/gists/${req.params.username}`);
});
// server-side redirect
app.get("/user-gists/:username", (req, res) => {
res.redirect(301, `/gists/${req.params.username}`);
});

if (
process.env.NODE_ENV !== "production" &&
process.env.NODE_ENV !== "test"
) {
app.use(morgan("dev"));
}
if (process.env.NODE_ENV !== "production" && process.env.NODE_ENV !== "test") {
app.use(morgan("dev"));
}

app.all(
"*",
createRequestHandler({
build: require("@remix-run/dev/server-build"),
getLoadContext() {
return { userId: 4 };
},
})
);
app.all(
"*",
createRequestHandler({
build: require("@remix-run/dev/server-build"),
getLoadContext() {
return { userId: 4 };
},
})
);

app.listen(port, () => {
console.log(`Gists app running on port ${port}`);
console.log(`http://localhost:${port}`);
});
app.listen(port, () => {
console.log(`Gists app running on port ${port}`);
console.log(`http://localhost:${port}`);
});
16 changes: 9 additions & 7 deletions packages/create-remix/cli.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { cli } from "@remix-run/dev";

cli.run(["create", ...process.argv.slice(2)]).then(
() => {
let args = process.argv.slice(2);

cli
.run(["create", ...args])
.then(() => {
process.exit(0);
},
(error: Error) => {
console.error(error);
})
.catch((error: Error) => {
console.error(args.includes("--debug") ? error : error.message);
process.exit(1);
}
);
});
2 changes: 1 addition & 1 deletion packages/remix-react/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ export function Meta() {
// Open Graph tags use the `property` attribute, while other meta tags
// use `name`. See https://ogp.me/
let isOpenGraphTag = name.startsWith("og:");
return [value].flatMap((content) => {
return [value].flat().map((content) => {
if (isOpenGraphTag) {
return (
<meta
Expand Down
10 changes: 10 additions & 0 deletions packages/remix-server-runtime/__tests__/sessions-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ describe("Cookie session storage", () => {
expect(setCookie).toContain("Path=/");
});

it("throws an error when the cookie size exceeds 4096 bytes", async () => {
let { getSession, commitSession } = createCookieSessionStorage({
cookie: { secrets: ["secret1"] },
});
let session = await getSession();
let longString = new Array(4097).fill("a").join("");
session.set("over4096bytes", longString);
await expect(() => commitSession(session)).rejects.toThrow();
});

describe("when a new secret shows up in the rotation", () => {
it("unsigns old session cookies using the old secret and encodes new cookies using the new secret", async () => {
let { getSession, commitSession } = createCookieSessionStorage({
Expand Down
9 changes: 8 additions & 1 deletion packages/remix-server-runtime/sessions/cookieStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ export const createCookieSessionStorageFactory =
);
},
async commitSession(session, options) {
return cookie.serialize(session.data, options);
let serializedCookie = await cookie.serialize(session.data, options);
if (serializedCookie.length > 4096) {
throw new Error(
"Cookie length will exceed browser maximum. Length: " +
serializedCookie.length
);
}
return serializedCookie;
},
async destroySession(_session, options) {
return cookie.serialize("", {
Expand Down

0 comments on commit 215749b

Please sign in to comment.