app.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * Intégrations des dépendences
  3. */
  4. const express = require('express');
  5. const morgan = require('morgan');
  6. const setup = require('./setup');
  7. const config = require('./config');
  8. /**
  9. * Intégration des routes stockées dans /routes
  10. */
  11. const voice = require('./routes/voice');
  12. const status = require('./routes/status');
  13. const call = require('./routes/call');
  14. const sms = require('./routes/sms');
  15. const get = require('./routes/get');
  16. const stream = require('./routes/stream');
  17. /**
  18. * Ajout du middleware d'authentification => vérifie si l'on utilise bien l'API avec un mot de passe
  19. */
  20. const auth = require('./middleware/authentification');
  21. if (config.setupdone == 'false') setup();
  22. /**
  23. * Partie express côté serveur web
  24. */
  25. var app = express();
  26. app.use(express.urlencoded({
  27. extended: true
  28. }));
  29. //app.use(morgan('combined')); // Only used for debug http requests
  30. app.post('/voice/:apipassword', auth, voice);
  31. app.post('/status/:apipassword', auth, status);
  32. app.post('/call', auth, call);
  33. app.post('/sms', auth, sms);
  34. app.post('/get', auth, get);
  35. app.get('/stream/:service', stream);
  36. app.use(function(req, res) {
  37. res.status(404).json({
  38. error: 'Not found, or bad request method.'
  39. });
  40. });
  41. module.exports = app;