Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(remix-dev): add serverEntryFile config option #4123

Closed
wants to merge 2 commits into from

Commits on Sep 2, 2022

  1. feat: Add option to specify server file for Remix App Server

    Currently if a dev wants to extend the configuration of Remix App Server, they
    must eject from RAS to the Express adapter. This PR adds a new config option 
    `serverEntryFile` that specifies the file that will be used by RAS instead of
    its default configuration. If the file is TypeScript, it will be transpiled
    automatically.
    
    ```js
    // remix.config.js
    module.exports = {
      serverEntryFile: './server.ts'
    }
    ```
    
    Running `npm run dev` will launch Remix App Server and import the server file.
    
    For production builds, the dev should update the `start` script to specify the
    server file for `remix-serve`. NOTE: If the server file is TypeScript, this must
    be transpiled manually during the build process.
    
    ```json
    "build": "remix build && npm run build:server",
    "build:server": "esbuild --format=cjs --platform=node --outfile=build/server.js server.ts",
    "start": "remix-serve build build/server.js",
    ```
        
    The server file should export the following functions:
    
    ```ts
    // REQUIRED: create the Express app and return it
    export function createApp(
      buildPath: string,
      mode = "production",
      publicPath = "/build/",
      assetsBuildDirectory = "public/build/"
    ): Express
    
    // OPTIONAL: create an HTTP/HTTPS server and return it
    function createServer(app: Express, port: number): Server
    
    // OPTIONAL: create a WebSocket server and return it
    function createSocketServer(port: number): WebSocket.Server
    ```
    kiliman committed Sep 2, 2022
    Configuration menu
    Copy the full SHA
    7451fd7 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    45f916d View commit details
    Browse the repository at this point in the history