Skip to content

Commit

Permalink
[NETTOYAGE] Supprime duplication
Browse files Browse the repository at this point in the history
… et protège la route `GET /oots/callback` par une variable
d'environnement au passage.
  • Loading branch information
egaillot committed Dec 2, 2024
1 parent 0ce05d2 commit c301d8a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
22 changes: 6 additions & 16 deletions src/routes/routesOOTS.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,13 @@ const routesOOTS = (config) => {
const { adaptateurEnvironnement, depotDonnees } = config;
const routes = express.Router();

routes.get('/document', (requete, reponse) => {
if (adaptateurEnvironnement.avecOOTS()) {
depotDonnees.demarreRecuperationDocument()
.then(() => reponse.render('redirectionNavigateur', { destination: urlOOTS(adaptateurEnvironnement, requete) }));
} else {
reponse.status(501).send('Not Implemented Yet!');
}
});
routes.get('/document', (requete, reponse) => depotDonnees
.demarreRecuperationDocument()
.then(() => reponse.render('redirectionNavigateur', { destination: urlOOTS(adaptateurEnvironnement, requete) })));

routes.post('/document', (requete, reponse) => {
if (adaptateurEnvironnement.avecOOTS()) {
depotDonnees.termineRecuperationDocument(Buffer.from(requete.body.document))
.then(() => reponse.send());
} else {
reponse.status(501).send('Not Implemented Yet!');
}
});
routes.post('/document', (requete, reponse) => depotDonnees
.termineRecuperationDocument(Buffer.from(requete.body.document))
.then(() => reponse.send()));

routes.get('/callback', (requete, reponse) => {
reponse.render('redirectionNavigateur', { destination: '/' });
Expand Down
9 changes: 8 additions & 1 deletion src/siteVitrine.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const creeServeur = (config) => {
journal,
middleware,
} = config;

let serveur;
const app = express();

Expand Down Expand Up @@ -46,7 +47,13 @@ const creeServeur = (config) => {
middleware,
}));

app.use('/oots', routesOOTS({ adaptateurEnvironnement, depotDonnees }));
const protegeRoute = (_requete, reponse, suite) => (
adaptateurEnvironnement.avecOOTS()
? suite()
: reponse.status(501).send('Not Implemented Yet!')
);

app.use('/oots', protegeRoute, routesOOTS({ adaptateurEnvironnement, depotDonnees }));

app.use('/', routesBase({ adaptateurEnvironnement, depotDonnees, middleware }));

Expand Down

0 comments on commit c301d8a

Please sign in to comment.