Home > Mobile >  After deploying a webpage, can the user change a source file?
After deploying a webpage, can the user change a source file?

Time:09-28

I want the user (non-public webpage, so only a few people will have access) to be able to save the field preference that they collectively want to keep when the webpage refreshes.

This currently works locally (localhost:3000), but I want to know if this will still work when the webpage is deployed/up and running

Fields menu, wanting to save preferences

Here is where I read in the .json file to look at the saved preferences

let CONFIG = require('../assets/savedFieldsPreferences.json');

This is if they choose to save new preferences, it'll send a request to the backend

<button onClick = {()=>{
                client2.send(JSON.stringify(State.values.Fields))
            }}style = {{marginTop: "1rem", height: "30px", fontSize: "16pt", fontWeight: "bold", backgroundColor: "lightblue"}}>Save Preferences (Will Reload Page)</button>

The backend writes to the .json file, and then the page will request to reload

const server2 = http.createServer();
server2.listen(8001);
const wsServer2 = new webSocketServer({
  httpServer: server2,
  maxReceivedFrameSize: 131072,
  maxReceivedMessageSize: 10 * 1024 * 1024,
  autoAcceptConnections: false
});

wsServer2.on('request', function(request) {
  var userID = 10;
  console.log((new Date())   ' Recieved a new connection from origin '   request.origin   '. 2');
  // You can rewrite this part of the code to accept only the requests from allowed origin
  const connection = request.accept(null, request.origin);
  clients[userID] = connection;
  connection.on('message', function(message) {
    //let fields = JSON.parse(message.utf8Data)
    let fs = require('fs');
    fs.writeFile('./sql-statistical-analysis/src/assets/savedFieldsPreferences.json', message.utf8Data, 'utf8', function(err) {
    if (err) throw err;
    //console.log('complete');
    });
  })
});

CodePudding user response:

Deploying isn't anything special. It will be running on computer, just like yours, nothing special.

You can actually test how it will behave with multiple users by opening multiple tabs of your programs or locally opening your program on different device. Device will have to be on the same network as your computer on which web server is running.

On your computer that is running he server open Command prompt and type ipconfig. You will see your local IPv4 address. Now take your phone, make sure it's connected to same network (WiFi, not mobile data) and in browser type in your IPv4 address of PC followed by port, so something like 192.168.0.98:3000. It should open your web page on your phone.

Problem that you will run into is that you store your preferences on your server. Meaning that they will be shared between everyone, 1 file for all the users. Meaning that if somebody will change them after refreshing the page it will be changed for everyone, since preferences are just whatever is saved in that 1 file on server.

If you want user specific preferences just use localStorage.

https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage

  • Related