Making a proxy for Roblox using Node.JS

I just wanna start with this by saying: i am like not very good with web development so like yeah it wont be the most optimized thing ever but it’ll work!

Hi! This tutorial will show you how to make basic web API’s for your roblox games. So, first of all.

Why would I use a web API?

There’s many reasons. For example – a bot to rank people if they buy a gamepass. A api to get the store of a game and send it to a roblox server. You can host a website if you want, and hook up a domain to it.

What should I keep in mind?

First of all, you’re probably going to need a VPS for this. Glitch works, although it isn’t always up so I use a paid one. You can even port forward, but that is a huge security risk so I wouldn’t recommend it.

Part 1

First, we’re making all of this in Node.js, so you’ll need that. If you don’t have it, click this.

Installing on Windows or MacOS: Download | Node.js (nodejs.org)
Installing on Linux (most vps’ run on this. run it in the terminal):

sudo apt update
sudo apt install nodejs

You’re going to need a code editor too. I use VS Code, and that’s what I’ll be using in the tutorial. So, start by opening up VS Code. You should see something like this:

Now, open up a folder (or make a new one.)

image

image

image

If you see this message, just click the blue button.
image

Now, we need to initialize our project. At the top, there should be a Terminal button. Click that, and then New Terminal. Now, type

npm init

And press enter 11-12 times. Also, we’re going to need a package for our web server. Type this in the terminal, and press enter:

npm i express

Now that we have it all setup, add a new file. We’ll name this server.js
image

image

Open up your new file. Now, we gotta put a few things in there.

var express = require("express")
var app = express()
var port = 2000

app.use(express.json())

app.listen(port)

But, what does this do. First, var defines a variable, just like local defines one in lua. Require is pretty similar to require in roblox. Because we installed express, we can now require that module and use its functions. But why do we call express? Calling express creates a new web server, which is what we want. Lastly, port is just what port it’ll run on. For example, port 80 would be localhost:80. We make it listen for that port, so if you go to localhost:80 in your browser it’ll show up what we have. For this tutorial, we’ll be making a proxy for the roblox API. Kind of like rprxy, but it’s self-hosted (so most times it will be faster!). Also, the app.use(express.json()) makes it so our web API will accept JSON.

To do this, we’re going to make a post request. So, we’re going to add this.

app.post("/ProxyGet", function(Request, Res){
    
})

What this does, is creates a new page in our api. (Web browsers cannot access it, because they make a GET request, not a POST request. When this is posted to, it runs the callback function we made, with two arguments. The request, and the Response. The response is to send what they want back, and the Request is to get what they want. Here is our code now:

var express = require("express")
var app = express()
var port = 2000

app.use(express.json())

app.post("/ProxyGet", function(Request, Res){
    
})

app.listen(port)

Now, we’re going to need another module for this, called “request”. To install this, type this in the terminal and press enter:

npm i request

Now, at the start of the code put this:

var request = require("request")

All this does it gets the request module, so we can use it to make an http request. This is our code now:

var express = require("express")
var request = require("request")
var app = express()
var port = 2000

app.use(express.json())

app.post("/ProxyGet", function(Request, Res){
    
})

app.listen(port)

Inside of our ProxyGet function, we’re going to put this.

app.post("/ProxyGet", function(Request, Res){
    if (!Request.body.url){
        Res.send("No url provided")
        return
    }

    var URL = Request.body.url

})

What this does, is checks if there is a url to make a request to. ! in if statements means if there is not, so we are checking if url is in the body. If not, we send our response, which is that there was No url provided, and then return (cancel the function). If there is a URL, we define that. Here is our new code:

var express = require("express")
var request = require("request")
var app = express()
var port = 2000

app.use(express.json())

app.post("/ProxyGet", function(Request, Res){
    if (!Request.body.url){
        Res.send("No url provided")
        return
    }

    var URL = Request.body.url

})

app.listen(port)

With our URL, we can now make the request. This is pretty simple. To do this, add this code:

app.post("/ProxyGet", function(Request, Res){
    if (!Request.body.url){
        Res.send("No url provided")
        return
    }

    var URL = Request.body.url
    request(URL).pipe(Res)

})

Great! What this does, is makes a GET request to the URL, and whatever it gets, it pipes it to the user. Basically, it asks something to the server, the server says something back, and we it tells it back to you. Here is all of our code:

var express = require("express")
var request = require("request")
var app = express()
var port = 80

app.use(express.json())

app.post("/ProxyGet", function(Request, Res){
    if (!Request.body.url){
        Res.send("No url provided")
        return
    }

    var URL = Request.body.url
    request(URL).pipe(Res)

})

app.listen(port)

Now that we have all of this done, let’s get it up and running.

Part 2

For this tutorial, I will be hosting it with DigitalOcean. This should work with other server hosts that can run Ubuntu. First, make sure you’ve saved your work. In visual studio, do CTRL + S. Now, we’re going to need three things.

puttygen
putty
FileZilla

First of all, open up puttygen. Click generate, and then move your mouse around until the green bar is gone.
image

Now, copy your public key onto your clipboard.
image

With that done, you should save your private key somewhere safe.
image

image

Now, let’s start our server. In digital ocean, click this:

image

Enter all the info, like so

Click skip for now.

Now, make a droplet.
image

Make sure its on Ubuntu. Here, I would choose the cheapest plan (cuz a proxy doesn’t need much power)

When you see this, click SSH Key. image

Under that, click New SSH Key

Paste in your key:

image

And click Add SSH Key. Select your key (if it isn’t selected), and then go down.

Click this:

And wait for it to create. Now that it’s all set up, click on your droplet and copy the IP

image

Now, open up putty. Paste your ip in this box:

image

Now, click the plus next to SSH, and then Auth

image

image

Now, click the Browse button, and look for the key you generated.

image

Now that you’re all ready, click Open.

image

Click Yes if this pops up.

image

Type root and press enter
image

Now, we’ll need to install two things. Type these comamnds

sudo apt update
sudo apt install nodejs
sudo apt install npm
npm install pm2 -g
sudo apt install nginx
sudo ufw allow 'Nginx HTTP'

If it asks you to type Y/n during any of the commands, just type y and press enter. With all of this done, your web server is up and running! But you aren’t fully done. Open up FileZilla. When you’re in, click File at the top, then Site Manager.
image

At the bottom, click New site.
image

Look for this dropdown, and click it.
image

Then, click SFTP
image

With that selected, go back to DigitalOcean and copy the ip again. Paste it into the Host box.

image

Change the Logon Type to Key file
image

image

Type root in the User box. Next to key file, click Browse.

image

Select the key file you generated
image

With all of that done, click Connect. Now, open up File Explorer, and look for the Folder you made for your Node.js server. Open it up. Now, in FileZilla, change Remote site to /

image

Now, we’re going to make a folder. Scroll all the way down and right click on an empty area. image

Click create directory. Name it server, and press ok

image

It’ll make a new directory. Look for it, and double click it. You should see a blank white screen. Now, open up File Explorer again, and select all your files. Drag em in there.

image

It’ll take a while. Leave your computer until this says 0 or has no number
image

Yay! It’s all done. Change your remote site to /etc/nginx/sites-available
image

Now, right click on default and click Download image

Copy the local site onto your clipboard

image

Then, go to it in file explorer. Look for a file called default
image

Now, right click it and click Open with
image

image

Click Visual Studio Code and then OK. In visual studio code, do CTRL + A, then backspace. Now, paste this:

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
server {
	listen 80 default_server;
	listen [::]:80 default_server;

	# SSL configuration
	#
	# listen 443 ssl default_server;
	# listen [::]:443 ssl default_server;
	#
	# Note: You should disable gzip for SSL traffic.
	# See: https://bugs.debian.org/773332
	#
	# Read up on ssl_ciphers to ensure a secure configuration.
	# See: https://bugs.debian.org/765782
	#
	# Self signed certs generated by the ssl-cert package
	# Don't use them in a production server!
	#
	# include snippets/snakeoil.conf;

	root /var/www/html;

	# Add index.php to the list if you are using PHP
	index index.nginx-debian.html;

	server_name hellonode;

	location ^~ /assets/ {
		gzip_static on;
		expires 12h;
		add_header Cache-Control public;
  }

	location / {
		proxy_http_version 1.1;
		proxy_cache_bypass $http_upgrade;

		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection 'upgrade';
		proxy_set_header Host $host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header X-Forwarded-Proto $scheme;

		proxy_pass http://localhost:2000;
		allow all;
	}
}

With all of this done, you can close VS Code. Go back to FileZilla. Open up File Explorer, and drag default into it.

Click OK, and then you should be good. In putty, type

systemctl restart nginx

Now, let’s get your code on here. In putty, type

cd /server
pm2 start server.js

And your server should be up and running! Try going to the ip in your web browser now. If you see this, it works!

image

Part 3

Make a new ModuleScript, and put this inside of it. Replace urlhere with your proxies url.

local HttpService = game:GetService("HttpService")
local Url = "http://urlhere/ProxyGet"
local Main = {}

function Main:GetAsync(myUrl)
	
	return HttpService:RequestAsync({
		
		Url = Url,
		Body = HttpService:JSONEncode({url = myUrl}),
		Headers = {
			["Content-Type"] = "application/json"
		},
		Method = "POST"
		
	}).Body
	
end

return Main

Now, put that modulescript inside your script, and you can use it like so:

local module = require(script.ModuleScript)
print(module:GetAsync("https://google.com"))

Please note, all url’s must start with http:// or https:// or it will fail.

Conclusion

So yeah that works I guess so pretty cool. Lmk if u want something else. I think this was my first tutorial cant remember

17 Likes