Skip to main content

Hide port for nodeJS app using App Manager

Comments

4 comments

  • pharmHalo
    I have tried a few new things today:
    • Created a copy of the APi under a different folder 'test'
    • made this port 3001 without using the FOREVER app
    I'm now getting into the app because I have cleaned up my app.js section but my routes are not working, all are coming up as "endpoint not found" using this as a 404 error response. Once again, if I use the port naming convention then this all works. This is how i am "listening": const port = process.env.port || 3001; const schedule = require('node-schedule'); const stripePayments = require('./api/routes/stripePayments'); const http = require('http'); const app = express(); app.use((req,res,next)=>{ res.header("Access-Control-Allow-Origin","*"); res.header("Access-Control-Allow-Headers","Origin,X-Requested-With,Content-Type,Accept,Authorization"); if (req.method === 'OPTIONS'){ res.header('Access-Control-Allow-Methods','PUT,POST,PATCH,DELETE,GET'); return res.status(200).json({}); } next(); }); //Routes (deleted except one) const chemistRoutes = require('./api/routes/chemists'); app.use('/chemists',chemistRoutes); app.use((req,res,next) => { const error = new Error('Endpoint not Found'); error.status = 404; next(error); }) app.use((error,req,res,next) => { res.status(error.status || 500); res.json({ error: { message: error.message } }); }); var server = http.Server(app); server.listen({port}, function(err){ });
    0
  • cPanelAnthony
    Hello! Regarding whether or not you can obscure the port number in this way, this wouldn't really be possible; at least not via any common methods that cPanel would utilize. It might be possible to do this via a rewrite proxy rule. However, you would have to get the conditions perfect and there would be a lot of room for error. I cannot guarantee this would work the way you need it to.
    0
  • pharmHalo
    Hi Anthony., Sorry my terminology probably wasnt correct. The idea is that I'm using the application manager so that my API calls will call the URL /myAPI instead of calling the port, This means i can close the port on iptables and reduce external exposure to the ports and just leave it as a URl call. So inreality everything is almost working with the exception of the routes arent being "seen" using the application manager path.
    0
  • cPanelAnthony
    Thank you for the confirmation! From my research, I am not finding a way to completely avoid the use of a port with a node.js app. I would highly recommend reaching out to a systems administrator if available to help determine if a solution like this would be possible. Otherwise, maybe other users on this forum will have some advice for you. Thank you for your understanding.
    0

Please sign in to leave a comment.