1

I'm currently facing something weird in my node js app.

I have two identical component in my express.js app.

1. Stock Vacations
2. Summer Stock Vacations

Each contains Model, Service, Controller and Route file.

stockVacations
  -> stockVacationController.js
  -> stockVacationModel.js
  -> stockVacationService.js
  -> stockVacationRoute.js

SummerStockVacations
  -> summerStockVacationController.js
  -> summerStockVacationModel.js
  -> summerStockVacationService.js
  -> summerStockVacationRoute.js

Both have the same collection fields in model and the same function name in service.js.

Now this is the order of my API:

const express = require('express');
const router = express.Router();

const StockVacation = require('./stockVacations/stockVacationRoute');
const SummerStockVacation = require('./summerStockVacations/summerStockVacationRoute');

router.use('/stock-vacation', StockVacation);
router.use('/summer-stock-vacation', SummerStockVacation);

module.exports = router;

And both route have route like this:

router.get('/', StockVacationController.getAll); // from stockVacation
router.get('/', SummerStockVacationController.getAll); // from stockVacation

Now, what's the issue is, this two apis:

http://localhost:3000/api/stock-vacation/?limit=10&page=1&year=2018
http://localhost:3000/api/summer-stock-vacation/?limit=10&page=1&year=2018

display the data of Summer Stock Vacation.

But If I change the order of calling the route file:

const SummerStockVacation = require('./summerStockVacations/summerStockVacationRoute');
const StockVacation = require('./stockVacations/stockVacationRoute');

Both, display the data of Stock Vacation.

So really weird to me. I don't understand why. Does anyone faced this issue before?

noyruto88
  • 767
  • 2
  • 18
  • 40

0 Answers0