Skip to content

Mocked server for developing FIveM resources without running an actual server

License

Notifications You must be signed in to change notification settings

antonstjernquist/fivem-mock-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FiveM Mock Server - FMS

Fivem Mock Server is a simple way of running your resource backend on a Node environment without needing to start your entire server.

This is a development resource.


Goal

The main goal of FMS is to allow a easy development server to run single resources when building them. You can easily set up endpoints for your mocked server & test them directly from the UI running like they would in FiveM.


Installation


The installation is quite straight forward. You basically need to setup the server to handle the requests from your NUI-client.

Server

import { MockServer } from 'fivem-mock-server';

new MockServer({
    isActive: true,
    resourceName: 'resouce-name',
    mysqlConnection: 'mysql://root:bruv@localhost/dev',
    players: [
        { // Source is 1
            name: 'Bingo',
            license: 'license:1'
        },
        { // Source is 2
            name: 'Player2',
            license: 'license:2'
        },
    ],
    exports{
        pefcl{
            openBank: () => { ... }
        }
    }
});

NUI

You need to use a specific url when in development to point the fetch to your mock server.

const resourceName = getResourceName();
const url = isDevelopment
? 'http://localhost:3005/${eventName.replace(':', '-')}'
: 'https://${resourceName}/${eventName}';

This will allow your requests using this function to


Full example for fetchNui function

export const fetchNui = async (
  eventName: string,
  data?: unknown,
) => {
  const resourceName = getResourceName();
  const url = isDevelopment
    ? `http://localhost:3005/${eventName.replace(':', '-')}`
    : `https://${resourceName}/${eventName}`;

  const options = {
    method: 'post',
    headers: {
      'Content-Type': 'application/json; charset=UTF-8',
    },
    body: JSON.stringify(data),
  };

  const res = await fetch(url, options);
  const response = await res.json();

  if (response.status === 'error') {
    throw new Error(response.errorMsg);
  }

  return response.data;
};

Additional Notes

Need further support? Join our Discord!

About

Mocked server for developing FIveM resources without running an actual server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published