main.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. .command('dev', 'start the Loquicompta server on 8080 port with verbose', (yargs) => {}, (argv) => {
  8. argv.port = 8080;
  9. argv.verbose = 1;
  10. })
  11. .option('port', {
  12. alias: 'p',
  13. default: 80
  14. })
  15. .option('auth', {
  16. default: true
  17. })
  18. .count('verbose')
  19. .alias('v', 'verbose')
  20. .count('sql')
  21. .alias('s', 'sql')
  22. .describe('p', 'port to bind')
  23. .describe('auth', 'disables authentication')
  24. .describe('v', 'show server informations')
  25. .describe('s', 'show sql informations')
  26. .argv;
  27. // Bibliotheques
  28. const express = require('express');
  29. // Creation variable globale
  30. global.app = express();
  31. global.verbose = argv.verbose >= 1;
  32. global.sqlVerbose = argv.sql >= 1;
  33. global.auth = argv.auth;
  34. // Configuration server
  35. app.use(express.json());
  36. require('./src/route');
  37. // Lancement serveur
  38. app.listen(argv.port, () => {
  39. console.info(`Server starting on port ${argv.port} (http://localhost:${argv.port})`);
  40. });