Я использую Gun DB и тестирование схемы пистолета.Я использую следующий код, но он не сохраняет данные в локальном хранилище - PullRequest
0 голосов
/ 27 февраля 2019

Подробное описание :: Я упомянул код двух файлов, приведенных ниже для справки.Библиотека схем оружия, которую я использую, не сохраняет данные в локальном хранилище.Я новичок в оружейной дБ и не имею никакого представления об этом.Кто-нибудь может мне помочь?упомянутые детали server.js :::: // импортировать собственный http-модуль

            var http = require('http')

            // import gun

            var Gun = require('gun')

            var server = http.createServer(function(req, res){
              if (Gun.serve(req, res)){ return } // filters gun requests!
              require('fs').createReadStream(require('path').join(__dirname, req.url)).on('error',function(){ // static files!

            res.writeHead(200, {'Content-Type': 'text/html'});

             res.end(

             require('fs')
                  .readFileSync(require('path')
                  .join(__dirname, 'index.html') // or default to index
                ));
              }).pipe(res); // stream
            });


            // start listening for requests on `localhost:8080`
            server.listen(8080)
        ------------------------------------------------------- 
    index.html ::::
        <!-- index.html -->
        <html>
          <head>
            <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
          </head>
          <body>
            <div id="App">
              <div id="Output"></div>
              <input
                type="text"
                id="Input"
                placeholder="Enter a message..."
                autofocus
              >
            </div>
            <script src="http://localhost:8080/gun.js"></script>
            <script>
              const gun = Gun('http://localhost:8080' + '/gun');

               const graphqlGun = require('graphql-gun');
               const Gun = require('gun');
               const gql = require('graphql-tag')

              // var jack  = gun.get('jack');
              // jack.put({name:'jack',occupation:'manager'})

              var fish = gun.get('fish');
              fish.put({red: {name: 'Frank'}});

              const $Input = document.querySelector('#Input');
              gun.get('test-input').val((data) => {
                $Input.value = data.value;
              })
              $Input.addEventListener('input', e => {
                const { value } = e.target;
                gun.get('test-input').put({
                  value
                });
              });

              let timestamp = 0;
              gun.get('test-input').on(function(data, key) {
                const ts = data._['>'].value;
                if (timestamp === ts) {
                  return;
                }
                timestamp = ts;
                console.log("update:", data);
                const $Output = document.querySelector('#Output');
                $Output.innerHTML = /* @html */`
                  <pre>
                    </code>
                      ${JSON.stringify(data, null, 2)}
                    
                  
`;});
...