0

What I want to do seems elementary; but, I am running into some blocks.

All I want to do is display pages based on a condition.

var express = require("express");
var app = express();

app.get('/', function(req, res) {
  if (userIsLoggedIn()) {
    res.sendFile(__dirname + '/public/index.html');
  } else {
    res.sendFile(__dirname + '/public/accessDenied.html');
  }
});

I am looking to grab information from the browser – I want to call a function from another browserify-ed file, and use the return value to determine which page is displayed to the user.

I can't run the server from app.js because it needs to be browserify-ed since it requires Web3. And since the function relies on state, I am not sure how to access this state from the server file.

TylerH
  • 20,799
  • 66
  • 75
  • 101
0TTT0
  • 1,288
  • 1
  • 13
  • 23
  • What do you mean *"grab information from the browser"*? Express is on the *server*, if it's coming from the browser it needs to be in the *request*. – jonrsharpe Feb 22 '19 at 22:01
  • well all I really need to do is grab data from the blockchain using web3 – 0TTT0 Feb 22 '19 at 22:03

1 Answers1

0

You have to post data from the browser to the server either with a form or query parameter.

For example:

web3.shh.post(object [, callback]) https://web3js.readthedocs.io/en/1.0/web3-shh.html#post

on the server site you need to extract those values and have to reply based on your posting.

How to process POST data in Node.js?

Unfortunately your use case is not clear ,but in general you might want to check out how to handle HTTP API communication.

TylerH
  • 20,799
  • 66
  • 75
  • 101
silverfighter
  • 6,762
  • 10
  • 46
  • 73