Replies: 3 comments 12 replies
-
Remix App Server is basically a batteries-included no-config option for running Remix apps. If you want more configuration, the solution is to use the Express adapter. I've written a script that will let you "eject" from RAS to Express. It uses the latest files from the Express template. Then you can edit server.js as much as you'd like. |
Beta Was this translation helpful? Give feedback.
-
What about adding an environment variable for overriding the |
Beta Was this translation helpful? Give feedback.
-
I've created a patch to allow you to specify the server file to use with Remix App Server. It even supports TS files. You just need to export a function named You can also export optional BTW: I had to create a new config option. The //server.ts
import { createRequestHandler } from "@remix-run/express";
import compression from "compression";
import express, { type Express } from "express";
import fs from "fs";
import https from "https";
import morgan from "morgan";
import WebSocket from "ws";
export function createApp(
buildPath: string,
mode = "production",
publicPath = "/build/",
assetsBuildDirectory = "public/build/"
) {
let app = express();
app.disable("x-powered-by");
app.use(function (req, res, next) {
res.setHeader("X-Powered-By", "TS Remix App Server");
next();
});
app.use(compression());
app.use(
publicPath,
express.static(assetsBuildDirectory, { immutable: true, maxAge: "1y" })
);
app.use(express.static("public", { maxAge: "1h" }));
app.use(morgan("tiny"));
app.all(
"*",
mode === "production"
? createRequestHandler({ build: require(buildPath), mode })
: (req, res, next) => {
delete require.cache[buildPath];
let build = require(buildPath);
return createRequestHandler({ build, mode })(req, res, next);
}
);
return app;
}
export function createServer(app: Express, port: number) {
const server = https
.createServer(
// Provide the private and public key to the server by reading each
// file's content with the readFileSync() method.
{
key: fs.readFileSync("server.key"),
cert: fs.readFileSync("server.crt"),
},
app
)
.listen(port, () => {
console.log(`server is running at https://localhost:${port}`);
});
return server;
}
export function createSocketServer(config: { devServerPort: number }) {
const server = https.createServer(
// Provide the private and public key to the server by reading each
// file's content with the readFileSync() method.
{
key: fs.readFileSync("server.key"),
cert: fs.readFileSync("server.crt"),
}
);
const socket = new WebSocket.Server({ server });
server.listen(config.devServerPort, () => {
console.log(
`socket server is running at https://localhost:${config.devServerPort}`
);
});
return socket;
} // remix.config.js
/** @type {import('@remix-run/dev').AppConfig} */
module.exports = {
ignoredRouteFiles: ["**/.*"],
serverEntryFile: "./server.ts",
// appDirectory: "app",
// assetsBuildDirectory: "public/build",
// serverBuildPath: "build/index.js",
// publicPath: "/build/",
}; |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Context
Here's a short twitter thread between myself and @kentcdodds that sparked this discussion.
Problem
I've just started a new project with the Indie Stack and I've deployed it straight to a single region on fly.io to take advantage of the excellent response times. I have a static asset that I want to be cached for users pretty much all the time, something like a logo. To accomplish this right now, I'd need to set up some config outside of my application, beginning a journey away from the simplicity of the Indie Stack that I opted for in the first place.
Proposal
remix.config.js
accepts options forremix-run/serve
that can be passed along to the express server that it starts. These would be a simple passthrough at the related points in the server setup, with the key of the option relating pretty much 1-1 to a line in the server startup.Example
The
static
object maps directly to the static middleware initialisation on this line and takes the config provided or falls back to the current default.This could potentially open the door to allowing other config to be manipulated with the same mechanism.
I'm not wedded to this mechanism at all and I can see that there might have to be an intermediary step required to take these options and persist them at run time outside the
remix.config.js
file (which I believe is not in the build artifacts). On first glance, from a DX perspective it seems like the place that this stuff should live.Beta Was this translation helpful? Give feedback.
All reactions