Как я могу избежать ошибки, что изображение не существует в кеше - GATSBY - PullRequest
0 голосов
/ 27 января 2020

Я использую Страпи и Гэтсби. Я хочу перестраивать Gatbsy каждый раз, когда что-то меняется в Strapi.

У меня есть один тип контента (bsixtbanner). Внутри / api / bsixtbanner / models / Bsixtbanner у меня есть следующий код:

const updateFrontend = require('../../../updateFrontend');

module.exports = { 

  // After creating a value.
  // Fired after an `insert` query.
  afterCreate: async (model, attrs, options) => {
    updateFrontend.updateFrontend();
  },  

  // After updating a value.
  // Fired after an `update` query.
  afterUpdate: async (model, attrs, options) => {
    updateFrontend.updateFrontend();
  },

  // After destroying a value.
  // Fired after a `delete` query.
  afterDestroy: async (model, attrs, options) => {
    updateFrontend.updateFrontend();
  }
};

И обновление интерфейса выглядит следующим образом:

const shell = require('shelljs');

module.exports = {
  updateFrontend: () => {
    // const path = "cd && cd Projects/dealers/frontend";
    // const actions = "kill -9 $(lsof -t -i:8000 -sTCP:LISTEN) && npm run clean && gatsby develop -H 0.0.0.0";

    const path = "cd /home/web";
    const actions = "bash release_frontend.sh";

    try {
      shell.exec(`${path} && ${actions}`, function(code, stdout, stderr) {
        if (code) {
          console.error(code);
          return;
        }
      });
    } catch (error) {
      console.log(error);
    }
  }
};

Когда я пробую его на localhost с:

const path = "cd && cd Projects/dealers/frontend";
const actions = "kill -9 $(lsof -t -i:8000 -sTCP:LISTEN) && npm run clean && gatsby develop -H 0.0.0.0";

Работает нормально, и содержимое обновляется.

Но когда я пытаюсь сделать это на сервере, с:

const path = "cd /home/web";
const actions = "bash release_frontend.sh";

Где release_frontend.sh следующим образом:

#!/bin/bash


cd /home/web/project/frontend
cp /var/www/frontend/gatsby-config.js gatsby-config.js

rm -rf .cache
rm -rf public
npm run clean
npm run build


cp gatsby-config.js /var/www/frontend/gatsby-config.js
cd public
cp -r * /var/www/frontend


echo Frontend Done !

Я получаю кучу ошибок как:

Encountered an error trying to infer a GraphQL type for: `ninth_banner_image_1___NODE`. There is no corresponding node with the `id` field matching: "/home/web/project/frontend/.cache/gatsby-source-filesystem/6b4e342a100b59958d193a7e332510bb.png absPath of file".

Эти ошибки связаны с gatsby cache Я думаю. Когда я получаю похожую ошибку на localhost, я делаю npm run clean, и ошибки исчезают.

Что я делаю не так?

...