main.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env node
  2. // Gestion des commandes et des options de l'application
  3. const argv = require('yargs')
  4. .command('serve [port]', 'start the Loquicompta server', (yargs) => {
  5. yargs.positional('port', {describe: 'port to bind', default: 80});
  6. }, (argv) => {
  7. })
  8. .command('dev', 'start the Loquicompta server on 8080 port with verbose', (yargs) => {
  9. }, (argv) => {
  10. argv.port = 8080;
  11. argv.verbose = 1;
  12. })
  13. .option('port', {
  14. alias: 'p',
  15. default: 80
  16. })
  17. .option('auth', {
  18. default: true
  19. })
  20. .count('verbose')
  21. .alias('v', 'verbose')
  22. .count('sql')
  23. .alias('s', 'sql')
  24. .describe('p', 'port to bind')
  25. .describe('auth', 'disables authentication')
  26. .describe('v', 'show server informations')
  27. .describe('s', 'show sql informations')
  28. .argv;
  29. // Chargement fichier config
  30. const config = require('./src/config');
  31. // Bibliotheques
  32. const express = require('express');
  33. // Creation variable globale
  34. global.app = express();
  35. if (!config.auth) {
  36. global.auth = false;
  37. } else {
  38. global.auth = argv.auth;
  39. }
  40. global.storage = config.storage;
  41. global.verbose = argv.verbose >= 1;
  42. global.sqlVerbose = argv.sql >= 1;
  43. // Configuration server
  44. app.use(express.json());
  45. require('./src/route');
  46. // Lancement serveur
  47. app.listen(argv.port, () => {
  48. console.info(`Server starting on port ${argv.port} (http://localhost:${argv.port})`);
  49. });