Host .json file like info.json or players.json

Hello everyone!
Im looking for the way to host my own .json file like /players.json or /info.json.
Ofc i can just make it by resource and then create virtual link to my web directory and then acces it for example by domain.com/thisfile.json, but im looking for way to acces it by server like domain.com:serverport/thisfile.json.
Any ideas ?

2 Likes

SET_HTTP_HANDLER, typically.

3 Likes

Thanks, but how to use it ? There is nothing in natives for it :frowning:
https://runtime.fivem.net/doc/natives/#_0xF5C6330C

Maybe look at runcode as example

3 Likes

I already did, i find some like this:

SetHttpHandler(function(req, res)
	local path = req.path


	if req.path == '/test' then
		res.send(json.encode({
			test = 'test'
		}))

		return
	end

end)

but its not working

Works here

5 Likes

Ahh, now its working. I tried to get into this by ‘ip:port/test’ instead of ‘ip:port/resourcename/test’. Now its working perfect, thanks so much, big heart for you <3

1 Like

Hi here ,

Still working ? :slight_smile:

Sure.

Hi,

i used your setup and its not working for me.

/test not responding , its be charging infinite loop

Add resource name in path between port and file name.
Like ip:port/resourcename/test instead of ip:port/test

Like :

localhost:30120/forklift/test ?

I reproduce ur example and doesnt work ^^

I tried also just seems to load infinitely.

Any chance any of you got it working lol?

it was posted above.

Unfortunately the code above doesn’t work.

Create your own topic with more info than just “doesn’t work” e.g. your code and what you tried.

1 Like