Hello, first time posting here.

I'm a javascript and node.js newbie and would like to ask for advice.

I'm making a node server which will accept requests from a chrome extension 
and a certain HTTP client.
I want the server to accept requests from the extension but only under a 
certain condition.
What I had in mind was to use the HTTP client to send a POST request to 
start or stop receiving requests from the extension.
Here is what I came up with:

const express = require('express');
const app = express();

process.env.MYTOGGLE = false;

app.post('/start', function (req, res){
// HTTP client lets the server accept requests
process.env.MYTOGGLE = true;
res.send('Accepting requests from extension...');
});

app.post('/request', function (req, res){
// extension requests go here
if(!process.env.MYTOGGLE){
res.send('404 Not Found');
} else { 
res.send('Thanks for the data!');
}
});

app.post('/stop', function (req, res){
// HTTP client changes the condition and requests to /request give '404 Not 
Found'
process.env.MYTOGGLE = false;
res.send('Not accepting requests anymore!');
});

app.listen(3000);

I've used environment variables as a demonstration to what I want to 
achieve in the end. 
Is there something I can use in order to store that 'toggle' variable on 
the server side and give the server access to it while it's running?

Or am I going about this the wrong way?

Much appreciated,
Anton


-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/f1ee4e2b-e853-4004-aff6-3265804a9671%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to