Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

MapreeDev/http-fivem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTTP

Overview

HTTP is a lightweight and simple HTTP server for FiveM, inspired by the syntax of Express.js. It aims to provide a familiar and easy-to-use framework for handling HTTP requests and building server-side logic in the FiveM environment.

Installation

  1. Download the required ox_lib dependency from the following link: ox_lib

  2. Extract the downloaded ox_lib archive and place it in the resources directory of your FiveM server.

  3. Clone the HTTP repository or download it from the following link: HTTP

  4. Extract the downloaded HTTP archive, remove "-fivem-main" from the name, and place it in the resources directory of your FiveM server.

  5. Include ox_lib and http in your server.cfg file:

    ensure ox_lib
    ensure http
  6. Start your FiveM server.

  7. Visit http://localhost:30120/http in your browser to see the default welcome message.

Features

Implemented

  • Basic routing with a familiar Express.js syntax.
  • Middleware support for handling requests.
  • Route query string parsing.
  • Support for handling GET, POST, and other HTTP methods.
  • Parse JSON body.
  • Parse cookies.
  • Static file serving.
  • Cors
  • Custom error handling.

Planned

  • Route params parser.
  • Session management.
  • WebSocket integration.
  • Integration with databases.
  • HTML Template support.
  • New version warning.
  • Refactor route search.

Under Development

  • Request validation and sanitization.

Usage

Routing

Define routes using Express.js syntax:

local express = require "@http.src.main"
local app = express()

app.get('/', function(req, res)
  res.send('Hello, FiveM!')
end)

Middleware

Use middleware functions to process requests before reaching route handlers:

app.use(function(req, res, next)
  print('Request received at', os.date())
  next()
end)

Listen

Use the listen function to make it live and listen on your FiveM server:

local listen = app.listen(function()
    print("Listening on the FiveM server\nExample: http://localhost:30120/"..GetCurrentResourceName().."/")
end)
SetHttpHandler(listen)

Example Project

For more examples, visit the file example/main.lua.

Contribution

Contributions are welcome! Feel free to open issues or submit pull requests to improve HTTP.

License

HTTP is licensed under the MIT License - see the LICENSE file for details.


Enjoy using HTTP in your FiveM server! If you have any questions or suggestions, feel free to reach out.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages