ExpressJS routes in different files

ExpressJS routes for the syndication stuff is now in a seperate file, will now do the other routes.

Signed-off-by: max <deadvey@localhost.localdomain>
This commit is contained in:
max
2025-09-23 17:38:20 +01:00
parent 5e4eb38763
commit 0541b704db
3 changed files with 92 additions and 77 deletions

View File

@@ -8,6 +8,7 @@
"date-fns": "^4.1.0",
"ejs": "^3.1.10",
"express": "^5.1.0",
"express-router": "^0.0.1",
"markdown-it": "^14.1.0",
"mysql": "^2.18.1",
"package.json": "^2.0.1"

85
src/routes/syndication.js Normal file
View File

@@ -0,0 +1,85 @@
const express = require('express');
const config = require('../../config')
const data = require('../data')
const func = require('../functions')
const router = express.Router();
////////////////////// SYNDICATION ////////////////////////
// global RSS protocol gets
router.get("/rss", (req,res) => {
if (config.rss == false) {
res.render("partials/message", {
message: locale.rss_disabled,
config,
})
}
else {
res.setHeader('content-type', 'application/rss+xml');
res.render("syndication/global_rss", {
config,
posts: data.getdata('posts'),
func,
})
};
});
// user RSS protocol gets
router.get("/user/:username/rss", (req,res) => {
const username = req.params.username;
const userID = func.get_userID(username);
if (config.rss == false) {
res.render("partials/message", {
message: locale.rss_disabled,
config: config,
})
}
else {
res.setHeader('content-type', 'application/rss+xml');
res.render("syndication/user_rss", {
config,
posts: data.getdata('posts'),
func,
userID,
})
};
});
// global ATOM protocol gets
router.get("/atom", (req,res) => {
if (config.atom == false) {
res.render("partials/message", {
message: locale.atom_disabled,
config: config,
})
}
else {
res.setHeader('content-type', 'application/rss+xml');
res.render("syndication/global_atom", {
config,
posts: data.getdata('posts'),
func,
getUnixTime,
})
};
});
// user ATOM protocol gets
router.get("/user/:username/atom", (req,res) => {
const username = req.params.username;
const userID = func.get_userID(username);
if (config.atom == false) {
res.render("partials/message", {
message: locale.atom_disabled,
config: config,
})
}
else {
res.setHeader('content-type', 'application/rss+xml');
res.render("syndication/user_atom", {
config,
posts: data.getdata('posts'),
func,
userID,
getUnixTime,
})
};
});
module.exports = router;

View File

@@ -61,83 +61,12 @@ app.use(express.static(config.root_path));
app.set('view engine', 'ejs');
app.set('views', '../views')
////////////////////// SYNDICATION ////////////////////////
// global RSS protocol gets
app.get("/rss", (req,res) => {
if (config.rss == false) {
res.render("partials/message", {
message: locale.rss_disabled,
config: config,
})
}
else {
res.setHeader('content-type', 'application/rss+xml');
res.render("syndication/global_rss", {
config,
posts,
func,
})
};
});
// user RSS protocol gets
app.get("/user/:username/rss", (req,res) => {
const username = req.params.username;
const userID = func.get_userID(username);
if (config.rss == false) {
res.render("partials/message", {
message: locale.rss_disabled,
config: config,
})
}
else {
res.setHeader('content-type', 'application/rss+xml');
res.render("syndication/user_rss", {
config,
posts,
func,
userID,
})
};
});
// global ATOM protocol gets
app.get("/atom", (req,res) => {
if (config.atom == false) {
res.render("partials/message", {
message: locale.atom_disabled,
config: config,
})
}
else {
res.setHeader('content-type', 'application/rss+xml');
res.render("syndication/global_atom", {
config,
posts,
func,
getUnixTime,
})
};
});
// user ATOM protocol gets
app.get("/user/:username/atom", (req,res) => {
const username = req.params.username;
const userID = func.get_userID(username);
if (config.atom == false) {
res.render("partials/message", {
message: locale.atom_disabled,
config: config,
})
}
else {
res.setHeader('content-type', 'application/rss+xml');
res.render("syndication/user_atom", {
config,
posts,
func,
userID,
getUnixTime,
})
};
});
// Express JS routes
var syndication_route = require('./routes/syndication.js');
//var route2 = require('./routes/rout');
app.use('/', syndication_route);
//app.use('/route2', route2);
///////////////////// Page index's ///////////////////////
app.get("/index/pages", (req,res) => {