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
1 Like

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

1 Like

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