@exortek/remix-fastify
v1.0.3
Published
Fastify server plugin for Remix
Downloads
80
Readme
@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:
- Create a new file in the root of your project called
server.mjs
. - 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}`);
});
- 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"
}
}
- Run the following command to start the server:
npm run dev
npm run start
OR
yarn dev
yarn start