diff --git a/.gitignore b/.gitignore index 5e9de5d3c..bb4e7d27a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ node_modules /.cache /server/build /public/build +/build \ No newline at end of file diff --git a/app/core/play/playerInfos/playerInfos.server.ts b/app/core/play/playerInfos/playerInfos.server.ts index 11baa4852..c5b1ff63d 100644 --- a/app/core/play/playerInfos/playerInfos.server.ts +++ b/app/core/play/playerInfos/playerInfos.server.ts @@ -1,38 +1,12 @@ -import fs from "node:fs"; -import path from "node:path"; -import z from "zod"; -import { weapons } from "~/constants"; import type { LookingLoaderData, LookingLoaderDataGroup, } from "~/routes/play/looking"; +import rawInfos from "./data.json"; -const infos = z - .record( - z.object({ - weapons: z.array(z.enum(weapons)).optional(), - peakXP: z.number().optional(), - peakLP: z.number().optional(), - }) - ) - .parse( - JSON.parse( - fs - .readFileSync( - path.join( - __dirname, - "..", - "..", - "app", - "core", - "play", - "playerInfos", - "data.json" - ) - ) - .toString() - ) - ); +const infos = rawInfos as Partial< + Record +>; export function addInfoFromOldSendouInk( type: "LEAGUE" | "SOLO", diff --git a/package.json b/package.json index d3f4db662..0e4f4704a 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "dev": "concurrently \"npm run dev:remix\" \"npm run dev:server\"", "postinstall": "remix setup node", "gen": "npx prisma generate", - "start": "cross-env NODE_ENV=production node ./server/build/index.js", + "start": "cross-env NODE_ENV=production node ./build/index.js", "migration:create": "npx prisma migrate dev --create-only", "migration:apply:dev": "npx prisma migrate dev", "migration:apply:prod": "npx prisma migrate deploy", diff --git a/remix.config.js b/remix.config.js index e0e08ddab..f703a655e 100644 --- a/remix.config.js +++ b/remix.config.js @@ -1,10 +1,13 @@ /** - * @type {import('@remix-run/dev/config').AppConfig} + * @type {import('@remix-run/dev').AppConfig} */ module.exports = { - appDirectory: "app", - browserBuildDirectory: "public/build", - publicPath: "/build/", - serverBuildDirectory: "server/build", - devServerPort: 8002, + server: "./server/index.js", + devServerBroadcastDelay: 1000, + //ignoredRouteFiles: [".*"], + // appDirectory: "app", + // assetsBuildDirectory: "public/build", + // serverBuildPath: "build/index.js", + // publicPath: "/build/", + // devServerPort: 8002 }; diff --git a/server/index.ts b/server/index.ts index c9470ddeb..c49f70f73 100644 --- a/server/index.ts +++ b/server/index.ts @@ -12,18 +12,30 @@ import { EventTargetRecorder, setUpEvents } from "./events"; import { setUpMockAuth } from "./mock-auth"; import { setUpSeed } from "./seed"; -const MODE = process.env.NODE_ENV; -const BUILD_DIR = path.join(process.cwd(), "server/build"); +import * as build from "@remix-run/dev/server-build"; + +const PUBLIC_DIR = path.join(process.cwd(), "public"); +const BROWSER_BUILD_DIR = "/build/"; const app = express(); app.disable("x-powered-by"); app.use(compression()); -// You may want to be more aggressive with this caching -app.use(express.static("public", { maxAge: "1h" })); - -// Remix fingerprints its assets so we can cache forever -app.use(express.static("public/build", { immutable: true, maxAge: "1y" })); +app.use( + express.static("public", { + setHeaders(res, pathname) { + const relativePath = pathname.replace(PUBLIC_DIR, ""); + res.setHeader( + "Cache-Control", + relativePath.startsWith(BROWSER_BUILD_DIR) + ? // Remix fingerprints its assets so we can cache forever + "public, max-age=31536000, immutable" + : // You may want to be more aggressive with this caching + "public, max-age=3600" + ); + }, + }) +); app.use(morgan("tiny")); @@ -66,37 +78,10 @@ function getLoadContext(req: Express.Request) { app.all( "*", - MODE === "production" - ? createRequestHandler({ - build: require("./build"), - getLoadContext, - }) - : (req, res, next) => { - purgeRequireCache(); - const build = require("./build"); - return createRequestHandler({ - build, - mode: MODE, - getLoadContext, - })(req, res, next); - } + createRequestHandler({ build, mode: process.env.NODE_ENV, getLoadContext }) ); const port = process.env.PORT ?? 5800; app.listen(port, () => { console.log(`Express server listening on port ${port}`); }); - -//////////////////////////////////////////////////////////////////////////////// -function purgeRequireCache() { - // purge require cache on requests for "server side HMR" this won't let - // you have in-memory objects between requests in development, - // alternatively you can set up nodemon/pm2-dev to restart the server on - // file changes, we prefer the DX of this though, so we've included it - // for you by default - for (const key in require.cache) { - if (key.startsWith(BUILD_DIR)) { - delete require.cache[key]; - } - } -}