From 99136954bb41a862ec79a788a17b7cc3ecd1252d Mon Sep 17 00:00:00 2001 From: Muthu Kumar Date: Mon, 30 Oct 2017 01:48:58 +0530 Subject: [PATCH] First module exported --- actions/createProxyServer.js | 46 ++++++++++++++++++++++---------------------- index.js | 3 ++- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/actions/createProxyServer.js b/actions/createProxyServer.js index f15dec3..dd50977 100644 --- a/actions/createProxyServer.js +++ b/actions/createProxyServer.js @@ -1,23 +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 +var fs = require('fs-extra') + +function createProxyServer(domain, 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" + + "}" + ) +} + +module.exports = createProxyServer \ No newline at end of file diff --git a/index.js b/index.js index 8431c21..9af6354 100644 --- a/index.js +++ b/index.js @@ -41,12 +41,13 @@ program .action(function(domain, port) { if(!isFQDN(domain)) console.log('\nDomain is not valid. Please use a valid domain name.') - else if(typeof port != 'number') + else if(typeof port !== 'number') console.log('\nPort should be a number.') // Stuff happens here //test stuff will be deleted later: else createProxyServer(domain, port) + console.log('Done!') //test stuff ends here })