gridsome.server.js 739 B

123456789101112131415161718192021222324252627
  1. const axios = require('axios'),
  2. fs = require('fs');
  3. let param = JSON.parse(fs.readFileSync('param.JSON', 'utf-8'))
  4. module.exports = function(api) {
  5. api.loadSource(async actions => {
  6. for (let d in param.meta) {
  7. actions.addMetadata(d, param.meta[d])
  8. }
  9. if (!param.search) throw "Nothing to search for";
  10. // Ajout des recherches
  11. let search = param.search.map(s => {
  12. return axios.get(`${param.source}${s}`);
  13. });
  14. await axios.all(search).then(res => {
  15. param.search.forEach((p, index) => {
  16. let action = actions.addCollection(p),
  17. {
  18. data
  19. } = res[index];
  20. for (const item of data) {
  21. action.addNode(item)
  22. }
  23. });
  24. });
  25. })
  26. }