Fix issue #19: Add unified campaign sync

This commit is contained in:
Gitea OpenCode Agent
2026-10-14 14:07:52 +00:00
parent 9d9738b2b4
commit 0a8452b3c8
22 changed files with 1469 additions and 921 deletions

View File

@@ -40,19 +40,22 @@ require('./services/passport')(passport);
// CORS
app.use(cookieParser());
const foundryCorsPaths = [
'/api/foundry/link/complete', '/foundry/link/complete',
// Services talk to Dragonroll from their own application (a Foundry world, an
// Obsidian vault, the Discord bot), so their link routes cannot be limited to
// one origin. What they may do is decided by the link code each of them holds.
const openCorsPaths = [
'/api/foundry/sync', '/foundry/sync',
'/api/link/start', '/link/start',
'/api/link/pickup', '/link/pickup',
];
const foundryCors = cors({
const openCors = cors({
origin: true,
methods: ['GET', 'POST', 'OPTIONS'],
allowedHeaders: ['Authorization', 'Content-Type'],
allowedHeaders: ['Authorization', 'Content-Type', 'X-Dragonroll-Discord-Bot-Secret'],
});
app.use('/api/foundry/link/complete', foundryCors);
app.use('/foundry/link/complete', foundryCors);
app.use('/api/foundry/sync', foundryCors);
app.use('/foundry/sync', foundryCors);
for (const path of openCorsPaths) {
app.use(path, openCors);
}
const appCors = cors({
origin: 'http://localhost:3000',
@@ -66,6 +69,11 @@ app.use((req, res, next) => {
// ROUTES (NO AUTH)
app.use('/api/user', require('./routes/user'));
app.use('/api/discord', require('./routes/discord'));
// The one way every service (Foundry, Discord, Obsidian) links itself to a
// campaign: it asks for a sign-up link, a user opens it and picks the campaign.
// Each service authenticates with its own proof: the Discord bot with its
// secret, Foundry and Obsidian with the link code they were handed.
app.use('/api/link', require('./routes/service-link'));
app.use('/api/foundry', require('./routes/foundry-link'));
app.use('/foundry', require('./routes/foundry-link'));