Browse Source

Working on proxy server module

pull/1/head
Muthu Kumar 7 years ago
parent
commit
34b40b37f2
  1. 4
      .gitignore
  2. 23
      actions/createProxyServer.js
  3. 35
      index.js

4
.gitignore

@ -1 +1,3 @@
node_modules
node_modules
test
test.txt

23
actions/createProxyServer.js

@ -0,0 +1,23 @@
var fs = require('fs-extra')
var domain = domain
var port = port
fs.outputFileSync("/test.txt",
"server {" + "\n" +
" listen 80;" + "\n" +
" listen [::]:80;" + "\n" +
" root /var/www/" + domain + ";" + "\n" +
" index index.html index.htm;" + "\n" +
"" + "\n" +
" server_name " + domain + "\n" +
" location / {" + "\n" +
" proxy_pass http://localhost:" + port + ";" + "\n" +
" proxy_http_version 1.1;" + "\n" +
" proxy_set_header Upgrade $http_upgrade;" + "\n" +
" proxy_set_header Connection 'upgrade';" + "\n" +
" proxy_set_header Host $host;" + "\n" +
" proxy_cache_bypass $http_upgrade;" + "\n" +
"}"
)
console.log('Done')

35
index.js

@ -5,9 +5,19 @@ var shell = require('shelljs')
var fs = require('fs-extra')
var chalk = require('chalk')
var validator = require('validator')
var createProxyServer = require('./actions/createProxyServer')
var isFQDN = validator.isFQDN
/* Use in prod
var isWin = /^win/.test(process.platform)
if(isWin == "Win32")
if (!shell.which('node')) {
shell.echo('I need NodeJS to work. Install nginx first. https://nodejs.org/');
shell.exit(1);
}
if (!shell.which('nginx')) {
shell.echo('I need nginx to work. Install nginx first. https://nginx.org/');
shell.exit(1);
@ -29,27 +39,14 @@ program
.command('proxy <domain> <port>')
.description('Create a proxy server, listening at port number.')
.action(function(domain, port) {
if(!isFQDN(domain)) console.log('\nDomain is not valid. Please use a valid domain name.')
if(typeof(port) != 'number') console.log('\nPort should be a number.')
if(!isFQDN(domain))
console.log('\nDomain is not valid. Please use a valid domain name.')
else if(typeof port != 'number')
console.log('\nPort should be a number.')
// Stuff happens here
//test stuff will be deleted later:
fs.outputFileSync("test",
"server {" + "\n" +
" listen 80;" + "\n" +
" listen [::]:80;" + "\n" +
" root /var/www/" + domain + ";" + "\n" +
" index index.html index.htm;" + "\n" +
"" + "\n" +
" server_name " + domain + "\n" +
" location / {" + "\n" +
" proxy_pass http://localhost:" + port + ";" + "\n" +
" proxy_http_version 1.1;" + "\n" +
" proxy_set_header Upgrade $http_upgrade;" + "\n" +
" proxy_set_header Connection 'upgrade';" + "\n" +
" proxy_set_header Host $host;" + "\n" +
" proxy_cache_bypass $http_upgrade;" + "\n" +
"}"
)
else
createProxyServer(domain, port)
//test stuff ends here
})

Loading…
Cancel
Save