Skip to content

ExorTek/remix-fastify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@exortek/remix-fastify

Fastify plugin for Remix.

Compatibility

Plugin version Fastify version
^1.x ^5.x

Installation

npm install @exortek/remix-fastify

OR

yarn add @exortek/remix-fastify

Usage

CommonJS:

const fastify = require('fastify');
const remixFastify = require("@exortek/remix-fastify");

const app = fastify();

app.register(remixFastify({
    buildDirectory: 'build', // default
    clientDirectory: 'client', // default
    serverDirectory: 'server', // default
    serverBuildFile: 'index.js', // default
    mode: process.env.NODE_ENV || 'development', // default
    fastifyStaticOptions: {}, // default
    viteOptions: {}, // default
}));

app.listen({port: 3000, host: 'localhost'}, (err, address) => {
    if (err) {
        console.error(err);
    }
    console.log(`Server listening at ${address}`);
});

ESM:

import fastify from 'fastify';
import remixFastify from "@exortek/remix-fastify";

const app = fastify();

app.register(remixFastify({
    buildDirectory: 'build', // default
    clientDirectory: 'client', // default
    serverDirectory: 'server', // default
    serverBuildFile: 'index.js', // default
    mode: process.env.NODE_ENV || 'development', // default
    fastifyStaticOptions: {}, // default
    viteOptions: {}, // default
}));

app.listen({port: 3000, host: 'localhost'}, (err, address) => {
    if (err) {
        console.error(err);
    }
    console.log(`Server listening at ${address}`);
});

How to use in Project

Set up your project as per the Remix documentation. Then, follow the steps below:

  1. Create a new file in the root of your project called server.mjs.
  2. Add the following code to the file:
import fastify from 'fastify';
import remixFastify from "@exortek/remix-fastify";

const app = fastify();

app.register(remixFastify({
    buildDirectory: 'build', // default
    clientDirectory: 'client', // default
    serverDirectory: 'server', // default
    serverBuildFile: 'index.js', // default
    mode: process.env.NODE_ENV || 'development', // default
    fastifyStaticOptions: {}, // default
    viteOptions: {}, // default
}));

app.listen({port: 3000, host: 'localhost'}, (err, address) => {
    if (err) {
        console.error(err);
    }
    console.log(`Server listening at ${address}`);
});
  1. Add the following script to your package.json:
{
  "scripts": {
    "dev": "cross-env NODE_ENV=development node server.mjs",
    "start": "cross-env NODE_ENV=production node server.mjs"
  }
}
  1. Run the following command to start the server:
npm run dev
npm run start

OR

yarn dev
yarn start

License

MIT