What's the port range users have at Glitch?

Hello Glitch

What’s the port range that can be used? As far as I know it’s only possible to use port 3000 to host a website, correct me if I’m wrong. If we have more ports than 3000, please let me know.

Thanks,
iHack2712

Right now we only expose only one port to the external world. If you want to expose more than one service, you might try with a reverse proxy, like the one offered by the http-proxy npm package. That way, you might have different services listening at various port, and then the proxy listening at port 3000: the proxy might then convert different urls into different ports, for example:

https://your-project.glitch.me/serviceA/:path -> http://localhost:4000/:path
https://your-project.glitch.me/serviceB/:path -> http://localhost:5000/:path
https://your-project.glitch.me/serviceC/:path -> http://localhost:6000/:path
4 Likes

Is there a sample project that implements this?

Hey, @kgashok

Take a look at this package (and it’s usage examples - they are pretty much similar as etamponi describes): https://www.npmjs.com/package/express-http-proxy

2 Likes

When I haven’t launched my app, my port on 3000 is free, right?
And if I want to run another tool which allows for the port to be set, as follows:

another_tool -s – port 3000

I should be able to go my app URL (http://myapp.glitch.me for e.g.) and view the output of that tool right? Or am I missing something?

That’s absolutely right :+1:

In the shell prompt, when I launch elm-analyse -s --port 3000 , I get the error,

Elm Analyser server starting with config:
{ port: '3000',
  elmFormatPath: 'elm-format',
  format: 'human',
  open: false }
events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE :::3000
    at Server.setupListenHandle [as _listen2] (net.js:1360:14)
    at listenInCluster (net.js:1401:12)
    at Server.listen (net.js:1485:7)
    at Function.serverListen [as listen] (/app/node_modules/express-ws/lib/index.js:40:28)
    at /app/node_modules/elm-analyse/dist/app/server/app.js:61:13
    at /app/node_modules/elm-analyse/dist/app/server/worker.js:30:9
    at /app/node_modules/elm-analyse/dist/app/util/dependencies.js:58:17
    at /app/node_modules/elm-analyse/dist/app/util/cache.js:66:13
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)

and a ps -aux shows me:

root     28756  0.0  0.0  19712  3220 pts/1    Ss   17:40   0:00 /bin/bash /etc/service/wetty/wetty-command.sh
root     28760  0.0  0.0  51004  3200 pts/1    S    17:40   0:00 su --preserve-environment --login app
app      28761  0.0  0.0  19984  3644 pts/1    S    17:40   0:00 -su
app      28918  0.0  0.0  19764  3264 ?        SNs  17:50   0:00 bash /opt/watcher/app-types/node/start.sh
app      28943  0.0  0.0  19764  1756 ?        SN   17:50   0:00 bash /opt/watcher/app-types/node/start.sh
app      28968  0.0  0.5 883724 37168 ?        SNl  17:50   0:00 node server.js
app      28997  0.0  0.0  36084  3072 pts/1    R+   17:53   0:00 ps -aux

are the processes running…

and a ss shows me these:

$ ss -tulw
Netid State      Recv-Q Send-Q                  Local Address:Port                                   Peer Address:Port                
udp   UNCONN     0      0                                   *:53471                                             *:*                    
tcp   LISTEN     0      128                                 *:1082                                              *:*                    
tcp   LISTEN     0      128                                 *:1084                                              *:*                    
tcp   LISTEN     0      128                                :::3000                                             :::*                    
tcp   LISTEN     0      128                                :::1081                                             :::*                    
tcp   LISTEN     0      128                                :::1083                                             :::*                    
tcp   LISTEN     0      128                                :::1085                                             :::*                    
tcp   LISTEN     0      128                                :::1086                                             :::*                    
tcp   LISTEN     0      128                                :::1087                                             :::*                    
tcp   LISTEN     0      128                                :::1088                                             :::*   

Are you 100% sure that your node app is not listening the 3000 port? Can you provide the project name or some part of code?

bitly-elm.glitch.me

Is the Project name. And it is an Elm app.

process.env.PORT listens to 3000 by default

1 Like

Oh! That’s where I need to look at!
What if I want elm-analyse also to be running concurrently? What are my options?

Can you help configure https://www.npmjs.com/package/express-http-proxy into this project for me so that I can use 3000 for the app, and 3001 for the elm-analyse output?

Thanks much!


One other thing: I would like elm-format to run whenever there is an edit that happens on *.elm files.

How do I set this up? Thanks much!

Can’t you copy the example?

const proxy = require('express-http-proxy')
const app = require('express')()

app.use('/elm', proxy(process.env.DOMAIN_NAME + '/elm'))

app.listen(3000)

watch.json

{ 
  ...
  "restart": {
    "*.elm",
    ...
  }
}

So, with those changes,
bitly-elm.glitch.me/elm -> my Elm application
and bitly-elm.glitch.me -> elm-analyse tool output?

Is that will be possible?

In my watch.json I already have,

{
  "restart": {
    "include": [
      "\\.elm$"
    ]
  },
  "throttle": 1000
}

Do I change that to what you have suggested?

1 Like
  1. Yes, try it out and report the results here (I hope it works)
  2. Looks strange; are you sure that the regexp \\.elm$ is matching your files?
1 Like

Will be it possible in the future to expose ports like 8443? I wish to build a telegram bot hosted on glitch but I am unable to since Telegram only suports the ports 443,80,88 and 8443 :frowning:

Source: https://core.telegram.org/bots/webhooks

Another part of Glitch proxies requests made to 80 and 443 on your glitch.me subdomain to your project container on port 3000. So that should be able to work with Telegram.

1 Like

@wh0 I didn’t understand. Can you elaborate. I tried using the telegram webhook but it didn’t work for me.

1 Like

Telegram would connect to a project subdomain like hello.glitch.me on say port 443. But hello.glitch.me doesn’t resolve to an IP address belonging to that project’s container. It resolves to a proxy server, and that proxy server receives the HTTP request. That proxy server connects to the project container on port 3000 and sends a copy of the request there.

So as far as Telegram is concerned, it is connecting to port 443. And as far as your project code is concerned, it’s receiving requests on port 3000. These should mean that overall it might be able to work, but…

I would have to take your word for it that it still doesn’t work. There are many other fiddly things about Glitch that could break it. Notably (i) there’s the system where it sometimes delivers a “Waking up” screen when your project container isn’t running, which has been known not to be friendly for anything other than a human sitting at a web browser, and (ii) they’re doing some not-publicly-detailed filtering to block abusive requests, which has been known to be disruptive for certain non-abusive integrations (1) (2).

5 Likes

Can this answer also be applied to my question?

My best guess is that it has something to do with Glitch being unable to connect with Telegram’s bot API.

I guess that’s one interpretation of glitch and telegram not connecting. although connections are directional when you look at them in more detail. this thread is about telegram connecting to glitch, and your thread, at least as titled, suggests a connection going from glitch to telegram. maybe that’s an unintentional bit of imprecision in the wording? or it might be precise and unrelated

1 Like