start api routes

This commit is contained in:
counterweight 2025-03-05 16:04:44 +01:00
parent db97f9fd80
commit c923493108
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
3 changed files with 290 additions and 273 deletions

View file

@ -18,11 +18,8 @@ function createApp(dependencies) {
app.use(dependencies.middlewares.createSessionMiddleware);
const webRoutes = dependencies.webRoutes;
const apiRoutes = require('./routes/apiRoutes');
app.use('/', webRoutes);
app.use('/api', apiRoutes);
app.use('/', dependencies.webRoutes);
app.use('/api', dependencies.apiRoutes);
app.use(express.static(path.join(__dirname, 'public')));

View file

@ -15,6 +15,10 @@ function buildDependencies() {
invitesService,
});
dependencies.webRoutes = webRoutesProvider.provide();
const ApiRoutesProvider = require('./routes/apiRoutes');
const apiRoutesProvider = new ApiRoutesProvider();
dependencies.apiRoutes = apiRoutesProvider.provide();
return dependencies;
}

View file

@ -16,12 +16,17 @@ const profileService = profileServiceProvider(ContactDetailsSet, NymSet);
const router = express.Router();
class ApiRoutesProvider {
constructor() {}
provide() {
router.get('/signup/nostr-challenge', async (req, res) => {
const inviteUuid = req.cookies.inviteUuid;
let signUpChallenge;
try {
signUpChallenge = await invitesService.createSignUpChallenge(inviteUuid);
signUpChallenge =
await invitesService.createSignUpChallenge(inviteUuid);
} catch (error) {
if (error instanceof errors.NotFoundError) {
return res.status(404).json({
@ -55,7 +60,9 @@ router.get('/signup/nostr-challenge', async (req, res) => {
});
}
return res.status(200).json({ challenge: relatedNostrChallenge.challenge });
return res
.status(200)
.json({ challenge: relatedNostrChallenge.challenge });
});
router.post('/signup/nostr-verify', async (req, res) => {
@ -118,7 +125,9 @@ router.get('/login/nostr-challenge', async (req, res) => {
});
}
return res.status(200).json({ challenge: relatedNostrChallenge.challenge });
return res
.status(200)
.json({ challenge: relatedNostrChallenge.challenge });
});
router.post('/login/nostr-verify', async (req, res) => {
@ -188,7 +197,10 @@ router.post(
});
}
await profileService.setContactDetails(publicKey, encryptedContactDetails);
await profileService.setContactDetails(
publicKey,
encryptedContactDetails
);
return res.status(200).json({
success: true,
@ -294,4 +306,8 @@ router.get(
}
);
module.exports = router;
return router;
}
}
module.exports = ApiRoutesProvider;