Jump to content

[Krydos] Issue with Fastify Route Registration on HelioHost Johnny (Node.js)


Recommended Posts

Posted (edited)

I'm running a Fastify application on Johnny and have structured my project to keep routes separate for maintainability. Instead of defining all routes in app.js, I have a routes/ folder where each route is stored in its own file.

For example, I have routes/apps.js, which looks like this:

 
	const knexConfig = require('../knexfile');  
	const knex = require('knex')(knexConfig.production);  
	const authMiddleware = require('../middlewares/auth');  
	 
	async function appRoutes(fastify, opts) {  
	  fastify.post('/addapps', { preHandler: authMiddleware }, async (request, reply) => {  
	    ... 
	}  
	module.exports = appRoutes;
	

 

In the main app.js, I have this:

	const fastify = require('fastify')({ logger: true });  
	async function main() {  
	  try {  
	    await fastify.register(require('./routes/apps'));  
	    fastify.get('/', async (req, reply) => {  
	      return { message: 'Ok!' };  
	    });  
	    await fastify.listen({ port: 3000, host: '127.0.0.1' });  
	  } catch (err) {  
	    fastify.log.error(err);  
	    process.exit(1);  
	  }  
	}  
	main();
	

 

The issue is that while the / route in app.js works just fine, any additional routes I place in routes/ do not work unless I manually define them inside app.js. I get the "not found" error.

{
	  "message": "Route GET:/addapps not found",
	  "error": "Not Found",
	  "statusCode": 404
	}

 

This defeats the purpose of splitting routes into separate files for maintainability.

 

Is there a limitation on Johnny preventing Fastify from loading external routes properly or is it a config issue on my path? How can I ensure all routes inside routes/ are correctly recognized when using fastify.register()?

I've attached a screenshot of my config. Thanks! 

 

Screenshot_20250321-153930.png

Edited by ujcis
Added the error message
Posted

I'm not sure if anyone here will know this one honestly. I've never even heard of Fastify until now, and have near-zero experience with Node.

Krydos would be the one who would know if anybody will. I wouldn't be surprised if this is to do with Passenger or how node works here. I assume this code works if you run it locally on your PC?

Escalating.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...