Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need to be more clear about Node and SEA, Node relay needs require (ES5 and not ES6) #1264

Closed
bitdom8 opened this issue Jul 23, 2022 · 6 comments

Comments

@bitdom8
Copy link

bitdom8 commented Jul 23, 2022

Checked react tutorial and learned that you need to install these 2 packages for node to be working. Need to be more clear as it takes more time to even install default node server:

npm install --save buffer text-encoding

I had "Signature did not match." on gundb data base a lot of times before fixing it

@bitdom8
Copy link
Author

bitdom8 commented Jul 24, 2022

The problem persists after few login and logout.

"Signature did not match." in gundb. When using this relay server ('https://gun-manhattan.herokuapp.com/gun',) it went away. How can it work with this default relay server and not with ours?

Wanna use my own relay server. Taken the code from here examples but still errs.

@bitdom8
Copy link
Author

bitdom8 commented Jul 24, 2022

Maybe I changed the relay node to ES6 script not using require but using import as below:

import cluster from "cluster";
import fs from "fs"
import Gun from 'gun'
import 'gun/sea.js';
import 'gun/lib/radix.js'
import 'gun/lib/radisk.js'
import 'gun/lib/store.js'
import https from "https"
import http from "http"
import path from 'path'
import {fileURLToPath} from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// import crashed from 
// cluster = cluster();
// require('../lib/crashed')
var gun

;(function(){
	
	if(cluster.isPrimary){
	  return cluster.fork() && cluster.on('exit', function(){ cluster.fork(); });
	}

	// var fs = require('fs');
	var config = {
		port: process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || process.argv[2] || 8765,
		peers: process.env.PEERS && process.env.PEERS.split(',') || []
	};
	// var Gun = require('../'); // require('gun')

	if(process.env.HTTPS_KEY){
		config.key = fs.readFileSync(process.env.HTTPS_KEY);
		config.cert = fs.readFileSync(process.env.HTTPS_CERT);
		config.server = https.createServer(config, Gun.serve(__dirname));
        
	} else {
		config.server = http.createServer(Gun.serve(__dirname));
	}

	gun = Gun({web: config.server.listen(config.port), peers: config.peers});

	console.log('Relay peer started on port ' + config.port + ' with /gun');

	// module.exports = gun;
	
}());

export {gun}

All works great until I refresh the page. Got an error "Signature did not match."

@bitdom8
Copy link
Author

bitdom8 commented Jul 24, 2022

Ok now understood you need to use ES5 with gun relay server and not ES6: please see here #636

Also a note with express. This is server.js file

console.log("If module not found, install express globally `npm i express -g`!");
var port    = process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || process.argv[2] || 8765;
var express = require('express');
var Gun     = require('gun');
require('gun/axe');

var app    = express();
app.use(Gun.serve);
app.use(express.static(__dirname));

var server = app.listen(port);
var gun = Gun({	file: 'data', web: server });

global.Gun = Gun; /// make global to `node --inspect` - debug only
global.gun = gun; /// make global to `node --inspect` - debug only

console.log('Server started on port ' + port + ' with /gun');

this is package.js file


{
	
	"type": "commonjs",
	
	"dependencies": {
	
		
	"express": "^4.18.1",
	
		
	"gun": "^0.2020.1237"
	
	}
}

@bitdom8 bitdom8 closed this as completed Jul 24, 2022
@bitdom8 bitdom8 changed the title Need to be more clear about Node and SEA Need to be more clear about Node and SEA, Node relay needs require (ES5 and not ES6) Jul 24, 2022
@bitdom8
Copy link
Author

bitdom8 commented Jul 24, 2022

Ok after few try again receive "User is already being created or authenticated!" from front end and "Signature did not match." in gundb relay server. Back to the beginning.

@draeder
Copy link
Contributor

draeder commented Jul 28, 2022

@bitdom8
You didn't post your client code, so I'm making assumptions here...

You need to wait until the user is created and/or authenticated before you can work with that user's graph.

gun.user().create('someuser', 'somepass') // authenticates automatically after user creation IIRC
// or
let pair = await SEA.pair()
gun.auth(pair)

// Wait for the `'auth'` event
gun.on('auth', ack => {
  if(ack.ok) console.log('user is authenticated') // now you can do stuff with the user's graph
})

@bitdom8
Copy link
Author

bitdom8 commented Jul 28, 2022

I had encountered with converting "require" statements on node relay server to import. My problem was rooted when just running the server and client side app, using sveltekit.

Now all is well with "require" on server "relay" side.

Had nothing to do with user or SEA but have seen this is issue most of the times. thanks @draeder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants