Browse Source

Working on fs

pull/1/head
Muthu Kumar 7 years ago
parent
commit
858e945d0b
  1. 41
      index.js
  2. 15
      test
  3. 15
      test.txt

41
index.js

@ -1,10 +1,10 @@
#!/usr/bin/env node --harmony
var program = require('commander');
var shell = require('shelljs');
var fs = require('fs-extra');
var chalk = require('chalk');
var validator = require('validator');
var program = require('commander')
var shell = require('shelljs')
var fs = require('fs-extra')
var chalk = require('chalk')
var validator = require('validator')
var isFQDN = validator.isFQDN
/* Use in prod
@ -21,7 +21,7 @@ program
.command('static <domain> [relativePath]')
.description('Create a static server at this folder.')
.action(function(domain) {
if(!isFQDN(domain)) console.log('Domain is not valid. Please use a valid domain name.')
if(!isFQDN(domain)) console.log('\nDomain is not valid. Please use a valid domain name.')
// Stuff happens here
})
@ -29,9 +29,28 @@ program
.command('proxy <domain> <port>')
.description('Create a proxy server, listening at port number.')
.action(function(domain, port) {
if(!isFQDN(domain)) console.log('Domain is not valid. Please use a valid domain name.')
if(typeof(port) != 'number') console.log('Port should be a number.')
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.')
// 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" +
"}"
)
//test stuff ends here
})
program
@ -66,8 +85,4 @@ program.on('--help', function(){
console.log('');
});
program.parse(process.argv);
if (program.peppers) {
console.log('\nPlease add domain name.\nExample: up static domain.name')
}
program.parse(process.argv);

15
test

@ -0,0 +1,15 @@
server {
listen 80;
listen [::]:80;
root /var/www/thefeathers.in;
index index.html index.htm;
server_namethefeathers.in
location / {
proxy_pass http://localhost:20;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}

15
test.txt

@ -0,0 +1,15 @@
server {
listen 80;
listen [::]:80;
root /var/www/thefeathers.in;
index index.html index.htm;
server_name DOMAIN.NAME
location / {
proxy_pass http://localhost:20;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
Loading…
Cancel
Save