Skip to content

Commit

Permalink
serve files through h2o
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoishin committed Feb 4, 2024
1 parent b2b9fce commit 8a88098
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 33 deletions.
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ services:
- ./local-proxy/h2o.yaml:/usr/local/etc/h2o.conf
- ./local-proxy/www.japanese-restream.org.localhost.pem:/ssl/cert.pem
- ./local-proxy/www.japanese-restream.org.localhost-key.pem:/ssl/key.pem
- ./build/client/assets:/www/assets
db:
image: postgres:16.1
volumes:
Expand Down
5 changes: 5 additions & 0 deletions local-proxy/h2o.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ hosts:
paths:
/:
proxy.reverse.url: http://host.docker.internal:3000
/assets:
file.dir: /www/assets
expires: 1 year
header.set:
- "X-Content-Type-Options: nosniff"
37 changes: 4 additions & 33 deletions src/server/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import * as path from "node:path";

import { fastifyCookie } from "@fastify/cookie";
import { fastifyHelmet } from "@fastify/helmet";
import { fastifyStatic } from "@fastify/static";
import {
createRequestHandler,
type RequestHandler,
Expand All @@ -13,7 +10,6 @@ import {
} from "@trpc/server/adapters/fastify";
import { fastify, type FastifyRequest } from "fastify";


import { env } from "../shared/env.server.js";

import { syncDataSource } from "./jobs/sync-data-source.js";
Expand All @@ -24,9 +20,10 @@ const server = fastify({
maxParamLength: 5000,
});

if (env.NODE_ENV === "production") {
await server.register(fastifyHelmet);
}
await server.register(fastifyHelmet, {
hsts: env.NODE_ENV === "production",
contentSecurityPolicy: false,
});

server.addContentTypeParser(
"application/x-www-form-urlencoded",
Expand All @@ -51,32 +48,6 @@ await server.register(fastifyTRPCPlugin, {
let handler: RequestHandler;

if (process.env.NODE_ENV === "production") {
await server.register(fastifyStatic, {
root: path.join(import.meta.dirname, "../build/client/assets"),
prefix: "/assets",
wildcard: true,
decorateReply: false,
cacheControl: true,
dotfiles: "allow",
etag: true,
maxAge: "1y",
immutable: true,
serveDotFiles: true,
lastModified: true,
});

await server.register(fastifyStatic, {
root: path.join(import.meta.dirname, "../build/client"),
prefix: "/",
wildcard: false,
cacheControl: true,
dotfiles: "allow",
etag: true,
maxAge: "1h",
serveDotFiles: true,
lastModified: true,
});

handler = createRequestHandler({
// @ts-expect-error - this is fine
build: await import("../../build/server/index.js"),
Expand Down

0 comments on commit 8a88098

Please sign in to comment.