add _cron/tick endpoint
This commit is contained in:
@@ -22,11 +22,22 @@ const apiRoot = config.apiPrefix || '/';
|
|||||||
app.use(apiRoot, createHealthRouter(config));
|
app.use(apiRoot, createHealthRouter(config));
|
||||||
app.use(apiRoot, createTodosRouter(config, db));
|
app.use(apiRoot, createTodosRouter(config, db));
|
||||||
|
|
||||||
|
app.post('/_cron/tick', (req, res) => {
|
||||||
|
const token = req.headers.authorization?.replace(/^Bearer\s+/i, '') || '';
|
||||||
|
const expected = process.env.CRON_TOKEN || '';
|
||||||
|
if (!expected || token !== expected) {
|
||||||
|
res.status(401).json({ success: false, error: 'Invalid cron token' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
res.status(200).json({ success: true, ticked: new Date().toISOString() });
|
||||||
|
});
|
||||||
|
|
||||||
const publicDir = path.join(__dirname, '../public');
|
const publicDir = path.join(__dirname, '../public');
|
||||||
app.use(express.static(publicDir));
|
app.use(express.static(publicDir));
|
||||||
|
|
||||||
app.get('*', (req, res, next) => {
|
app.get('*', (req, res, next) => {
|
||||||
if (req.path.startsWith(apiRoot)) return next();
|
if (req.path.startsWith(apiRoot)) return next();
|
||||||
|
if (req.path === '/_cron/tick') return next();
|
||||||
res.sendFile(path.join(publicDir, 'index.html'), (err) => {
|
res.sendFile(path.join(publicDir, 'index.html'), (err) => {
|
||||||
if (err) next();
|
if (err) next();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user