Express Router partially working

Hey,

I’ve incorporated Express Routing in my Glitch project (Yep im making an API service) and for a strange reason, only some of my router files custom.js, effects.js, generators.js, gif.js are working in the same directory (/Routes) while my other 2 (overlays.js and text.js) are not working. They pretty much use the same code (which i will show).

Working Router (generators.js)

const express = require('express');
const router = express.Router();
const { get } = require('node-superfetch');

router.get('/', function(req, res) {
    res.redirect('/docs');
});

const rateLimit = require("../utils/ratelimits")
//router.use(rateLimit.test);

router.use('/3000years', require('../Canvas/generators/3000years'));

module.exports = router;

Broken (text.js)

const express = require('express');
const router = express.Router();
const { get } = require('node-superfetch');

router.get('/', function(req, res) {
    res.redirect('/docs');
});

const rateLimit = require("../utils/ratelimits")
//router.use(rateLimit.test);

let hangmanword = require('../JSON/text/hangman');
  router.get('/hangmanrandoms', function (req, res) {
let hangmanwordrandom = hangmanword[Math.floor(Math.random() * hangmanword.length)]
    res.send(({word: hangmanwordrandom}))
  });

module.exports = router;

Yes, they look very identical but why is this happening? I renamed the files and same thing happen. Routing is working perfectly for 4 of my files but not the other two.

Project: ichigo-api-rewrite

Hm, I just found that this is also occurring when I create new routes, not just my existing ones.

How exactly do you check if the code is working or not? Which paths are you requesting?

I’ll invite you to the project and show what I mean, if you are okay with that?

https://ichigo-api-rewrite.glitch.me/text/hangmanrandoms
https://ichigo-api-rewrite.glitch.me/overlays/approved?image=https://i.imgur.com/BZSBrmP.jpg

Seems like I resolved it, it was the 404 Not Found affecting it (Even though its placed at the bottom of the code).

I’m guessing coz I can’t see the calling code …

Probably because the first router didn’t match, so the 404 was triggered.

You might set it up better by creating a single router, then pass it to each module to add its routes.

1 Like