У меня есть два маршрута в server.js
:
app.use("/credit/success", require("./credit/credit-handler"));
app.use("/credit/fail", require("./credit/credit-handler"));
И credit-handler
:
const express = require("express");
const router = express.Router();
// @route GET credit success
// @desc Get credit success screen
// @access Public
router.get("/success", async (req, res) => {
try {
res.sendFile("./credit/SuccessTransaction.html");
} catch (err) {
console.error(err.message);
res.status(500).send("Server Error :" + err.message);
}
});
// @route GET credit failure
// @desc Get credit fail screen
// @access Public
router.get("/fail", async (req, res) => {
try {
res.sendFile("./credit/FailTransaction.html");
} catch (err) {
console.error(err.message);
res.status(500).send("Server Error :" + err.message);
}
});
module.exports = router;
Как передать запрос /credit/success
на функцию success
, а запрос /credit/fail
к функции fail
в роутере?