Aller au contenu principal

Custom Routes

NodeCG uses express for its routing, and exposes a helper for creating routes easily:

bundles/my-bundle/extension.js
module.exports = function(nodecg) {
const router = nodecg.Router();

router.get('/customroute', (req, res) => {
res.send('OK!');
});

nodecg.mount('/my-bundle', router); // The route '/my-bundle/customroute` is now available
};

NodeCG has a Login Security Middleware that is by default not enabled. To enable it, you need to add it. This won't work unless Security & Authentication is enabled.

bundles/my-bundle/extension.js
module.exports = function(nodecg) {
const router = nodecg.Router();

router.use(nodecg.util.authCheck); // All routes using "router" will need a `?key=` in it's URL to be avaliable

router.get('/customroute', (req, res) => {
res.send('OK!');
});

nodecg.mount('/my-bundle', router); // The route '/my-bundle/customroute` is now available
};