Skip to content

Commit

Permalink
feat: http2 server
Browse files Browse the repository at this point in the history
  • Loading branch information
macrozone committed Jul 17, 2024
1 parent 26209f1 commit 76f953d
Show file tree
Hide file tree
Showing 5 changed files with 322 additions and 183 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ COPY --from=production-deps /myapp/node_modules /myapp/node_modules
COPY --from=build /myapp/node_modules/.prisma /myapp/node_modules/.prisma

COPY --from=build /myapp/build /myapp/build
COPY --from=build /myapp/server /myapp/server
COPY --from=build /myapp/public /myapp/public
ADD . .

Expand Down
3 changes: 2 additions & 1 deletion app/routes/turbo.api.v8.artifacts.$hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ export const action: ActionFunction = async ({ request, params, context }) => {
}

const storage = new CacheStorage();
const contentLength = Number.parseInt(request.headers.get('Content-Length') as string);

const contentLength = Number.parseInt((request.headers.get('Content-Length') as string) ?? 0);
try {
await Promise.all([
// The real type of request.body is ReadableStream. Somehow ReadableStream can be used as AsyncIterator
Expand Down
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
"typecheck": "tsc -b && tsc -b cypress && tsc -b prisma",
"validate": "run-p \"test -- --run\" lint typecheck test:e2e:run",
"prestart": "prisma migrate deploy && prisma db seed",
"start": "cross-env NODE_ENV=production remix-serve build/index.js"
"start": "cross-env NODE_ENV=production node server/index.mjs"
},
"dependencies": {
"@heroicons/react": "2.0.18",
"@prisma/client": "^5.8.1",
"@remix-run/node": "2.3.1",
"@remix-run/react": "2.3.1",
"@remix-run/serve": "2.3.1",
"@remix-run/node": "2.10.3",
"@remix-run/react": "2.10.3",
"@tanstack/react-table": "8.10.7",
"abstract-blob-store": "3.3.5",
"aws-sdk": "2.1551.0",
Expand All @@ -43,6 +42,8 @@
"domain-functions": "2.5.1",
"fs-blob-store": "6.0.0",
"isbot": "3.7.1",
"koa": "^2.15.3",
"koa-static": "^5.0.0",
"npm-run-all": "4.1.5",
"prisma": "^5.8.1",
"prop-types": "15.8.1",
Expand All @@ -58,6 +59,7 @@
"remix-auth-microsoft": "^2.0.1",
"remix-auth-oidc": "1.0.0",
"remix-forms": "2.2.1",
"remix-koa-adapter": "^2.0.0",
"remix-utils": "^7.3.0",
"s3-blob-store": "4.1.1",
"superjson": "2.2.1",
Expand All @@ -69,8 +71,8 @@
"zod": "3.22.4"
},
"devDependencies": {
"@remix-run/dev": "2.3.1",
"@remix-run/eslint-config": "2.3.1",
"@remix-run/dev": "2.10.3",
"@remix-run/eslint-config": "2.10.3",
"@tailwindcss/typography": "0.5.10",
"@testing-library/cypress": "^10.0.1",
"@testing-library/dom": "9.3.4",
Expand Down
22 changes: 22 additions & 0 deletions server/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Koa from "koa";
import serve from "koa-static";
import http2 from "node:http2";
import { createRequestHandler } from "remix-koa-adapter";
import * as build from "../build/index.js";
const app = new Koa();

app.use(serve("public"));

app.use(
createRequestHandler({
build,
})
);

const server = http2.createServer(app.callback());

const port = process.env.PORT;
server.listen(port, () => {
console.log(`server listening on port ${port}`);
// ... code to run after your server is running goes here ...
});
Loading

0 comments on commit 76f953d

Please sign in to comment.