gridsome.server.js 711 B

1234567891011121314151617181920212223242526
  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. let search = param.search.map(s => {
  11. return axios.get(`${param.source}${s}`);
  12. });
  13. await axios.all(search).then(res => {
  14. param.search.forEach((p, index) => {
  15. let action = actions.addCollection(p),
  16. {
  17. data
  18. } = res[index];
  19. for (const item of data) {
  20. action.addNode(item)
  21. }
  22. });
  23. });
  24. })
  25. }