diff --git a/.gitignore b/.gitignore index b512c09..b407659 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -node_modules \ No newline at end of file +node_modules +test +test.txt \ No newline at end of file diff --git a/actions/createProxyServer.js b/actions/createProxyServer.js new file mode 100644 index 0000000..f15dec3 --- /dev/null +++ b/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') \ No newline at end of file diff --git a/index.js b/index.js index bc2eff9..8431c21 100644 --- a/index.js +++ b/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 ') .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 })