Coder Social home page Coder Social logo

katon's Introduction

katon


Note except if you need a particular feature in katon, please use hotel. Hotel is cross-platform and doesn't require admin privileges to be installed.

A huge thank you to all the people who contributed to katon!


Access your dev servers by their names

katon is a development tool that makes dev servers accessible on beautiful local .ka domains. It also autostarts/stops them for you.

katon supports any server: Node, Ruby, Python, Go, Java, PHP, ... that can be started with a command-line and runs on OS X.

Linux, Windows

Please use hotel.

Install

Make sure Node is installed first, then:

$ npm install -g katon

To manually install katon, you can run sudo katon install && katon start.

Known issue: if Apache is running, it needs to be stopped to avoid conflict with katon.

Add servers

$ katon add 'nodemon'
$ katon add 'npm start'
$ katon add 'grunt server'
$ katon add 'rails server --port $PORT'
$ katon add 'python -m SimpleHTTPServer $PORT'
$ katon add 'php -S 127.0.0.1:$PORT'

To add a server with a different name than its directory.

$ katon add 'grunt server' my-custom-name
Application is now available at http://my-custom-name.ka

Note: it's important to use ' and not " to avoid $PORT to be evaluated.

Port is dynamically set by katon using PORT environment variable but can be passed as a parameter using $PORT.

In case your server doesn't accept a port parameter, you can retrieve the PORT environment variable in your code. For example, for a Node server you would write something like:

var port = process.env.PORT || 3000;

The same technique can be applied with other languages too.

How it works

  • When you add a server using the katon add command, its configuration is saved locally to ~/.katon/hosts/<app> and an equivalent ~/.katon/logs/<app> directory is also created.
  • The server is not started until you make your first request to your <app>.ka domain.
  • If no request is made to your <app>.ka server within an hour, then katon automatically stops it. Therefore, Katon automatically manages resources by starting only needed servers and stopping them when they're not used.

Subdomains

When adding a server, you can access it by its URL http://app.ka. But you can also use subdomains (e.g. http://foo.app.ka, http://bar.app.ka, ...).

If you want to map a server to a subdomain, let's say api.app.ka, simply use katon add <cmd> api.app.

Access from other devices

Using xip.io you can access your servers from other devices (iPad, iPhone, ...) on your LAN.

# Let's say your local address is 192.168.1.12
http://<app_name>.192.168.1.12.xip.io/

You can find your local address using ifconfig or going to index.ka

Remote access behind NAT/firewall

Using ngrok.com you can share access to your servers with others, when running behind a firewall or NAT.

First, follow the instructions to install ngrok, then register on the site to enable custom subdomains.

Then run ngrok with your application name as the subdomain:

ngrok http -subdomain app_name 80

This exposes port 80 to the internet on app_name.ngrok.io. Use at your own risk: all of your web hosts are accessible on this port while ngrok is running.

Access using HTTPS

You can also use HTTPS to access your servers https://<app_name>.ka.

Logs

Server logs are stored in ~/.katon/logs/<app_name>.log, to view them you can use:

$ katon tail [app_name]
$ katon tail all # View all logs

Version managers

katon works with any version manager, simply set the desired version before adding your server and katon will remember it.

$ nvm use 0.11 && katon add 'npm start'
$ rbenv local 2.0.0-p481 && katon add 'rails server --port $PORT'

Depending on your version manager, you may need to add environment variables.

$ rvm use ruby-2.0.0-p576 && katon add 'bundle exec unicorn' --env GEM_PATH
# Will use GEM_PATH previously set by rvm

For Node users, to keep access to katon CLI accross Node versions, add an alias to your .profile and reopen the Terminal.

echo "alias katon=`which katon`" >> ~/.profile

Troubleshoot

Run katon status or check ~/.katon/daemon.log.

If you're stuck, feel free to create an issue.

Uninstall

$ npm rm -g katon

This will run the uninstall script wich does basically katon stop && sudo katon uninstall. To remove katon completely, run also rm -rf ~/.katon.

Credits

  • Pow for daemon inspiration.
  • Powder for CLI inspiration.

License

katon is released under the MIT License.

katon's People

Contributors

ajb avatar assaf avatar hlegendre avatar jsierles avatar kematzy avatar nook-scheel avatar rjacoby avatar typicode avatar wcp1231 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

katon's Issues

Add index page to list added apps

I think it will be more convenience, not need to list apps in Terminal.

Like this: show apps in index.ka
meaningfulURL

or this: show apps in localhost
localhost

xip.io does not work?

xip.io isn't working when I ping app.ka.192.168.178.88.xip.io it returns my IP but when I load it in the browser nothing.

Accessing by IP 192.168.178.88 from even my local computer doesn't work.

I assume this an firewall issue. Any thoughts?

Support apps with multiple hostnames

I have one app with three sub-domains (www, static and admin).

I got it to work by creating symbolic links in ~/.katon, so I have three links to the same directory, which also means it first up three servers. Not the worst thing in the world, but have to wait longer for app to reload.

Would it be feasible for Katon to recognize all three link lead to the same app, and share one server between all three?

Pow "Couldn't proxy request to localhost:4000"

In my express app I set the port with:

app.set('port', process.env.PORT || 3000);

and i run katon link and the log shows:

PORT=4001 /usr/local/share/npm/lib/node_modules/katon/lib/daemon/../../node_modules/.bin/nodemon app.js15 Feb 12:10:17 - �[33m[nodemon] v1.0.14�[39m
15 Feb 12:10:17 - �[33m[nodemon] to restart at any time, enter `rs`�[39m
15 Feb 12:10:17 - �[33m[nodemon] watching: *.*�[39m
15 Feb 12:10:17 - �[32m[nodemon] starting `node app.js`�[39m
Express server listening on port 4001

but when I go to the specified url I get:

Proxy Error
Couldn't proxy request to localhost:4000.
Error: connect ECONNREFUSED

so then I change the app to:

app.set('port', 4000);

And refresh my browser and everything starts working...
Am I supposed to "hard code" the port like that? Or am I doing something wrong?

Error: ENOENT, open '/etc/resolv.conf'

This has happened randomly 3 times now, where Katon will just fail to work. Usually I do a npm uninstall and re-install and it's all good and dandy. However the last time, I just started it up, and it started working again.

This is the error that re-occures in the daemon.log

3 Oct 09:37:56 - �[31m[daemon] �[39mStart
3 Oct 09:37:56 - �[31m[daemon] �[39mLoading procs
3 Oct 09:37:56 - �[36m[procs ] �[39mAdd �[90mrealty�[39m
3 Oct 09:37:56 - �[36m[procs ] �[39mAdd �[90mroommates�[39m
3 Oct 09:37:56 - �[36m[procs ] �[39mAdd �[90mtruck�[39m
3 Oct 09:37:56 - �[31m[daemon] �[39mStarting DNS server on port 13375
3 Oct 09:37:56 - �[31m[daemon] �[39mStarting katon server on port 31000
3 Oct 09:37:56 - �[31m[daemon] �[39mDNS server started
3 Oct 09:37:56 - �[31m[daemon] �[39mKaton server started

/usr/local/lib/node_modules/katon/node_modules/native-dns/lib/platform.js:166
      throw err;
            ^
Error: ENOENT, open '/etc/resolv.conf'

Blank Page

Hello,

I installed everything as described, executing "katon link" outputs "Application is now available at mysite.dev", but all I see is a blank page.

Any ideas? Is this a Pow problem?

Also, it says the app is available at that URL but I don't see any log coming into terminal (link when using nodemon app.js). Does Katon output logs to the Terminal ?

Thanks

Windows support

Are you goring to support windows? What is the main problem with that?

PHP Server Not Routing

i can get to the to the app using localhost:{port}, but going to it via the .ka domain results in the “can’t connect, possible reasons: ...”.

[katon] Starting societysouth.dev on port: 31004 using command: php -S localhost:31004

halp :)

NVM support

I use NVM to vendor my node binaries on my dev machine. It seems that katon doesn't handle that at the moment. Is this something that could be supported first-class by the project? If not, do you have any ideas about how I can get the two to play together nicely? I tried creating a nodemon.json file in my project and point at the NVM node executable path directly, but that file seems to be getting largely ignored, based on what I can see being output in katon.log.

Add site with multiple commands

katon add 'cd site/; gulp;'

This isn't working and outputs:

[katon] Starting basicmodal on port: 31002 using command: cd site/ [object Object] gulp [object Object]

Maybe it's not supported or a bug, but whatever the reason is, it might be good to show an error.

Thanks for the great tool!

feature request: katon open w/ https instead of http

It would be really nice to have an option to use https instead of http when using katon open. Maybe even force ssl, redirect to https. Also, it was really awesome to discover that ssl was even setup for katon 🙌, maybe add a section for "ssl" or "https" to the docs? That was first thing I searched for.

If anyone else is interested in this, I just manually edited the following file in my global node modules directory - https://github.com/typicode/katon/blob/master/src/cli/commands/open.js#L9

Stop daemon after period of inactivity

Would be great if katon could optionally automatically stop a daemon if it hasn't been accessed in a while (perhaps some user-configurable duration).

Feature request: log viewing

Would be nice to go to katon.ka/log/myappname to see the logs. (bonus for an in-browser tail -f implementation!)

This would be great to be linked from index.ka as well.

Apache fighting with Katon

My Apache configuration on Yosemite starts Apache automatically when my computer boots up. I had been wrestling with Katon and it would work one minute but not another. I remembered that Apache was running. Once I stopped Apache, Katon seemed to run like a champ.

Wondering if anyone else can confirm the issue. Just thought I'd give some insight since there may be a lot os OS X users whose Apache could be causing some issues. It may be good to put "Stop Apache" in set up instructions if this is indeed an issue.

pause / resume commands

I'm curious as to whether you think having katon pause and katon resume would be valuable options. the objective here would be turning a server "off" (potentially saving resources) w/o losing it's configuration, as you would with katon rm.

I'm new to the project, so there may be architectural reasons this doesn't make sense - but I'm willing to contribute this if you thought it was worthwhile.

katon install & status doesn't work in tmux

I installed it:

$ sudo katon install
Installing katon
Done

Typing katon status says that it's not installed: (trying this twice produces the same result

$ katon status
Checking that katon daemon is loaded...
OK
Checking .ka domain...
KO try `sudo katon install`

I tried installing it again:

$ sudo katon install
Installing katon
katon.firewall: Already loaded
Done

Any tips on how to debug this? Katon 0.6.5, Node 0.10.32, OSX 10.9.5.

execvp(): No such file or directory

Just starting out with katon. Seems promising.

I have a LinemanJS project. The build/start-server command is lineman run and is configured as the npm-start script.

katon.log:

[katon] Start /Users/user/.katon/coordinator on port 4001
[katon] Starting `lineman run`
execvp(): No such file or directory

Re-linked via katon link 'lineman clean run' and .katon is created successfully. However, I get the same error in katon.log:

[katon] Start /Users/user/.katon/coordinator on port 4001
[katon] Detected .katon
[katon] Starting `lineman clean run`
execvp(): No such file or directory

Thoughts? Lineman is installed globally (via npm install -g lineman).

$ which lineman 
/usr/local/share/npm/bin/lineman

Katon + PHP integration issue

When running a symfony2 site over the php built in web server after about 10 requests I get the following error

Warning: Unknown: failed to open stream: Too many open files in Unknown on line 0

When I do a lsof -p on the php process i get a 500+ similar to -

php   2353 $USER  368u  IPv4 0xd28da1814874ee0b       0t0      TCP localhost:58215->localhost:etlservicemgr (CLOSED)

php     2353 $USER  369u  IPv4 0xd28da18142565fab       0t0      TCP localhost:58239->localhost:etlservicemgr (CLOSED)

php     2353 $USER  370u  IPv4 0xd28da18141a5353b       0t0      TCP localhost:58259->localhost:etlservicemgr (CLOSED)

php     2353 $USER  371u  IPv4 0xd28da18141a51acb       0t0      TCP localhost:58261->localhost:etlservicemgr (CLOSED)

Defiantly an issue to how katon is running the php process as it doesn't seem to happen when I run the php server from the command line.

Scenario: already existing webserver

I want to ask about this scenario: I have already existing webserver at localhost:3000. I start it manually from command line. I don't want to change this. Is there a way to simply create a .ka domain for that webserver and server it's requests exactly as they are from the new .ka domain? The webserver serves dynamic, generated content. To say it the other way I don't want Katon to launch the process(es) or watch filesystem.

It would be a really nice simplification if katon would allow cli command like:
katon link foofoo.ka localhost:3000
katon link barbar.ka localhost:3001
No process starting, no folders, no watching etc.

can start script have higher precedence than main?

A common scenario for me is to have a module with both a "main" file and a "start" script. The main file is for consumption by external modules and doesn't listen on a port at all. The start script does listen, and typically runs a server for in-browser tests, manual debugging, or examples. The current behavior of "main" having precedence over "start" doesn't work in this scenario, so I'm wondering if it can be reversed, or if there are scenarios where the current precedence makes more sense.

Katon doesn't route after clean install

Fresh install on new machine.

Katon says it installed and started OK. But status fails, as does trying to hit an app created with katon add.

It appears to be listening on the correct ports, and returning a faux DNS entry but not talking to the server?

➜  name_generator  curl http://katon-status-test.ka
curl: (7) Failed connect to katon-status-test.ka:80; Connection refused

➜  name_generator  curl http://katon-status-test.ka:31000
<!DOCTYPE html>
<html>
<head>
  <title>Katon</title>
  <style>


➜  ~  netstat -an |grep 31000
tcp4       0      0  *.31000                *.*                    LISTEN
➜  ~  netstat -an |grep 13375
udp4       0      0  *.13375                *.*

The /etc/resolver/ka entry looks corrupted (the '%' shows up in reverse color text on my terminal) but even removing the oddness with vim didn't help:

➜  ~  cat /etc/resolver/ka
# Katon
nameserver 127.0.0.1
port 13375%

Here's how I did everything:

➜  ~  node -v
v0.10.31
➜  ~  sudo katon install
Installing katon
Done
➜  ~  katon start
Starting katon daemon
Done
➜  ~  katon status
Checking that katon daemon is loaded...
OK
Checking .ka domain...
KO try `sudo katon install`


➜  name_generator  katon add 'harp server --port $PORT'
Application is now availaible at http://name-generator.ka/

➜  .katon  cat daemon.log
15 Sep 16:21:47 - [daemon] Start
15 Sep 16:21:47 - [daemon] Loading procs
15 Sep 16:21:47 - [procs ] Add name-generator
15 Sep 16:21:47 - [daemon] Starting DNS server on port 13375
15 Sep 16:21:47 - [daemon] Starting katon server on port 31000
15 Sep 16:21:47 - [daemon] DNS server started
15 Sep 16:21:47 - [daemon] Katon server started
15 Sep 16:22:02 - [dns   ] Received request for name-generator.ka
15 Sep 16:22:02 - [dns   ] Received request for name-generator.ka
15 Sep 16:23:14 - [dns   ] Received request for katon-status-test.ka
15 Sep 16:23:14 - [dns   ] Received request for katon-status-test.ka

I'm on Mac OS 10.9.4.

Any further debug help appreciated.

Opening localhost:4000 crashes the deamon process

When I open localhost:4000 I get the following error. I saw this when I tried to start the deamon manually, but I guess it is the same. The problem is that localhost:4000 is quite common to use.

undefined:43
__out.push(__sanitize(this.app.cwd));
^
TypeError: Cannot read property 'cwd' of undefined
at Object.eval (:43:37)
at Object.eval (:55:8)
at eval (:57:6)
at Function.eco.render (/usr/local/lib/node_modules/katon/node_modules/eco/lib/index.js:26:25)
at module.exports (/usr/local/lib/node_modules/katon/lib/render.js:11:16)
at ProxyServer. (/usr/local/lib/node_modules/katon/lib/daemon/proxy/index.js:59:26)
at ProxyServer.emit (/usr/local/lib/node_modules/katon/node_modules/http-proxy/node_modules/eventemitter3/index.js:79:10)
at ClientRequest.proxyError (/usr/local/lib/node_modules/katon/node_modules/http-proxy/lib/http-proxy/passes/web-incoming.js:127:16)
at ClientRequest.EventEmitter.emit (events.js:117:20)
at Socket.socketErrorListener (http.js:1547:9)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:440:14
at process._tickCallback (node.js:419:13)

FYI: local-tld & ports

Heya, I’ve been looking at this problem space for a while and last year wrote local-tld, a kinda port of pow to node and ports, a system-wide port registry.

This is less a “you should use this”, but you might be interested in checking them out :)

Centralised logging

Logging should be moved to ~/.katon/logs/APP_NAME.log. Currently the logging clutters up the working directory also makes it difficult to run 2 katon applications from the same directory.

Feature request: follow XDG base directory specification

I would like to see Katon follow the XDG base dir spec.

If I understand katon correctly, the files placed under $HOME/.katon are runtime-related files? They ought to be placed in $XDG_RUNTIME_DIR/katon.

For a smooth transition, we could use the $XDG_RUNTIME_DIR only if it exists and fall back to $HOME/.katon. This would leave XDG support as purely opt-in.

Not recognising pow installation

Katon status says I need to install pow even though it's installed. Running the install steps for the boilerplate express server works but my app returns:
An error has occurred: {"code":"ECONNREFUSED","errno":"ECONNREFUSED","syscall":"connect"}
Katon.log still shows the correct debug info I'd usually get in the command line.

*** Installing Pow 0.4.1...
*** Installing local configuration files...
*** Starting the Pow server...
*** Performing self-test...
*** Installed

For troubleshooting instructions, please see the Pow wiki:
https://github.com/37signals/pow/wiki/Troubleshooting

To uninstall Pow, `curl get.pow.cx/uninstall.sh | sh`
> katon status
Pow not installed, try katon install-pow
Katon daemon started
> katon restart
Katon daemon was successfully stopped
Katon daemon was successfully started
> katon status
Pow not installed, try katon install-pow
Katon daemon started

Katon breaking MAMP hosts

After I installed Katon, all my MAMP PRO hosts like local.example.com simply doesn't work anymore! My /etc/hosts file looks fine, any ideas what might be causing it?!

katon and RVM - not finding gems?

Having an issue using katon with rvm. Using the following:

rvm use ruby-2.0.0-p576 && katon add 'bundle exec unicorn -p 9999'

Getting the following:

/Users/omarvelous/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/gems/2.0.0/gems/bundler-1.7.3/lib/bundler/spec_set.rb:92:in `block in materialize': Could not find rake-10.3.2 in any of the sources (Bundler::GemNotFound)

It seems to be looking in the wrong spot for the gems? Not sure what's going on. Any guidance?

Omar

Katon + Docker integration

Hi all, really like katon and docker (for different reasons). However it occured me that it would be cool to have a plugin for katon that can pipe requests to a docker container. So this is not an issue more of a discussion as to:

  • is this possible? (Yes, see dirty script below)
  • should it be core code? or a plugin? (if so any pointers)
  • use case? (As a developer I want katon to find the correct running docker container for the project I am currently working on)

Below is a nodejs script which I copy'n'paste within each project. Then I create a katon host with:

$ katon add 'node proxy.js -p $PORT' app-name

Script:

// @todo needs to OS agnostic (only works on macs)
// @todo throw exceptions when prerequisites are not there e.g. docker!?
var shell = require('shelljs'),
    argv = require('minimist')(process.argv.slice(2)),
    httpProxy = require('http-proxy'),
    proxy
;

createProxy();

function createProxy() {
    if(proxy) {
        proxy.close();
    }

    var dockerIp = shell.exec('boot2docker ip 2>/dev/null', {silent: true}).output;
    dockerIp = dockerIp.match(/(\d+\.){3}\d+/g)[0];

   // NOTE: the app-name in the regex, docker container for a given project needs to be named exactly to match
    var containerPort = shell.exec('$(boot2docker shellinit) && docker ps', {silent: true}).output
        .match(/(\d+)->\d+\/[a-z]{3}\s+app-name/)[1];

    var target = 'http://' + dockerIp + ':' + containerPort;
    console.log('proxy to', target);

    proxy = httpProxy.createProxyServer({target: target}).listen(argv.p).on('error', function(e) {
        if(e.code === 'ECONNREFUSED') {
            createProxy();
            return
        }
        console.log('Unknown proxy error: ', e);
        throw e;
    });
}

The code above works surprisingly well, even when I restart the container, but could be a lot better "out of the box"

Don't assume port sequences?

Right now katon seems to assume it can just increment up through ports starting at 4001...

The issue I have is that meteor runs it's own copy of the app on port + 1, so running a meteor app takes port 4001 and port 4002. This means the next app can't start on 4002.

Can we change katon to detect if a port is in use before it tries to use it? If one is taken, just increment up until it finds an open port?

Add with different name

My site is located in a folder named etc/. This is actually not the name I want to use for the domain (etc.ka). It would be great if I could add the folder with a custom name:

katon add 'nodemon' --name myapp
katon add 'nodemon' -n myapp

Start apps when requested instead of on start up of katon

Currently katon starts apps when katon starts up. I would rather only start apps when they are requested by DNS to keep the running app cost down. This mimics pow and would be ideal for me as I have 30+ apps I would put in place.

KO try `sudo katon install`

Hi, I just don't seem to be able to get this to work. I always get KO try sudo katon install when running katon status
I'm not sure what info would be useful. I'm pretty much fully up to date on a Mac OSX... Yosemite, npm node all latest version

Rails: Command '--port' not recognized

Everything was working great until I tried katon reload, although I'm not positive that's what caused it. I am using katon 0.9.1 and added my server using: katon add 'rails server --port $PORT'

I'm unable to access my 'proj.ka' site and when running katon log I see:

[katon] Starting admin on port: 31030 using command: rails server --port 31030
bin/rails:6: warning: already initialized constant APP_PATH
/Users/jason/proj/bin/rails:6: warning: previous definition of APP_PATH was here
Error: Command '--port' not recognized
Usage: rails COMMAND [ARGS]

So maybe katon isn't running rails server --port 31030 directly? Since that command works fine in the terminal.

I'm using rails 4.1.7 and rbenv 0.4.0 if that matters.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.