Advertisement
Guest User

JS async

a guest
Mar 25th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const axios = require('axios')
  2.  
  3. const CONFIG_URL = "https://download.djaul.com/config.php"
  4.  
  5. async function getWebConfig() {
  6.     console.log("getWebConfig")
  7.    
  8.     let result;
  9.     try{
  10.         result = await axios
  11.         .get(CONFIG_URL)
  12.     }catch(e){
  13.         console.log(e);
  14.     }
  15.    
  16.     return result;
  17. }
  18.  
  19. function setLocalConfig(data) {
  20.     console.log("setLocalConfig")
  21.  
  22.     return {
  23.         debug: true,
  24.         server_name: data.server_name,
  25.         url: {
  26.             logo: data.logo_url,
  27.             site: data.site_url,
  28.             discord: data.discord_url,
  29.             forum: data.forum_url,
  30.             vote: data.vote_url,
  31.             files: data.files_url,
  32.             clientDownload: data.download_url,
  33.             updater: data.updater_url
  34.         },
  35.         menu: [
  36.             { label: "Mettre à jour" },
  37.             { label: "Lancer Djaul" },
  38.             { label: "Voter sur RPG" },
  39.             { label: "Quitter le launcher" }
  40.         ]
  41.     }
  42. }
  43.  
  44. //create an async function that can use `await`
  45. async function runConfig(){
  46.     const webConfig = await getWebConfig();
  47.     const localConfig = setLocalConfig(webConfig);
  48. };
  49.  
  50. runConfig();
  51.  
  52. module.exports = localConfig
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement