Git Product home page Git Product logo

tunnel.now's Introduction

tunnel.now

Zeit's now platform is fantastic for rapid iteration on Node.js projects. But sometimes - when debugging a webhook, for example - you might want to run your project on your development machine, somehow handling the requests from there.

Of course, you could make changes, deploy to now, and update the alias as you go. However, this project provides an alternative for those times when you want a faster iteration cycle before deploying a final version to the cloud: it tunnels HTTP requests that are sent to now to your local dev machine.

Quick start

Step 1: Install

$ npm install -g tunnel.now
/Users/dbustad/.nodenv/versions/8.0.0/bin/tunnel.now -> /Users/dbustad/.nodenv/versions/8.0.0/lib/node_modules/tunnel.now/src/tunnel.js
added 79 packages in 4.609s

Step 2: Update npm links (optional)

This step is only necessary for users of nodenv.

$ nodenv rehash

Step 3: Deploy your tunnel endpoint

$ tunnel.deploy
tunnel.now host has been deployed to tunnelnow-qtsdkdfibi.now.sh
Done!

You can also alias directly at this step, like so:

$ tunnel.deploy my-alias.now.sh
tunnel.now host has been deployed to tunnelnow-qtsdkdfibi.now.sh
setting alias "my-alias.now.sh"...

> tunnel.divmain.com is a custom domain.
> Verifying the DNS settings for my-alias.now.sh (see https://zeit.world for help)
> Verification OK!
> Success! my-alias.now.sh now points to tunnelnow-qtsdkdfibi.now.sh! [802ms]

Done!

Note that this deployment can be re-used however many times you'd like.

Step 4: Start your application server

In your project, do whatever you need to do to start your server, and take note of the port that is opened:

$ npm run start
Listening on port 8080...

In this case, that's port 8080.

Step 5: In a separate terminal, start your tunnel

tunnel.now takes two arguments:

  1. The now hostname. This will be either the hostname that now provided to you, or the alias that you specified during step 3. That's my-alias.now.sh in the example above.
  2. The port one which your locally-running application is listening. That's 8080 in the example above.
$ tunnel.now my-alias.now.sh 8080
Connected to wss://my-alias.now.sh:443.
Tunneling requests to http://localhost:8080...

Step 6: Open your browser!

Any HTTP requests made to the now hostname or alias will be tunneled to your local machine.

FAQ

Does this work with other services? Yes. The only hard requirement is that the host provides HTTP and WebSocket support. However, you will need to deploy the tunnel.now repo yourself.

License

This project is covered under the MIT License. Please see the LICENSE file for more information.

tunnel.now's People

Contributors

divmain avatar

Stargazers

Kavish Devar avatar Roman avatar Jeremy Kahn avatar Jaime Leonardo Suncin Cruz avatar Jacob Ford avatar Vladi Bilonenko avatar Mykola Harmash avatar Eric Bailey avatar Thomas avatar Nick Beattie avatar Josh Gwosdz avatar Kevin Segal avatar Joshua Alpuerto avatar Jared Palmer avatar Leonard Souza avatar Gabriel Almeida avatar Ricardo Casares avatar Viliam Kopecký avatar

Watchers

 avatar  avatar

tunnel.now's Issues

Headers are not correctly set

git:master $ curl 'https://tunnelnow-zzz.now.sh/translate/phrase' -X OPTIONS -H 'Access-Control-Request-Method: POST' -H 'Origin: http://localhost:3000' -H 'Referer: http://localhost:3000/' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36' -H 'Access-Control-Request-Headers: content-type' -v
*   Trying 104.18.124.144...
* TCP_NODELAY set
* Connected to tunnelnow-zzz.now.sh (104.18.124.144) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/cert.pem
  CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-CHACHA20-POLY1305
* ALPN, server accepted to use h2
* Server certificate:
*  subject: CN=*.now.sh
*  start date: Nov 26 14:15:26 2018 GMT
*  expire date: Feb 24 14:15:26 2019 GMT
*  subjectAltName: host "tunnelnow-zzz.now.sh" matched cert's "*.now.sh"
*  issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x7fa661802600)
> OPTIONS /translate/phrase HTTP/2
> Host: tunnelnow-zzz.now.sh
> Accept: */*
> Access-Control-Request-Method: POST
> Origin: http://localhost:3000
> Referer: http://localhost:3000/
> User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36
> Access-Control-Request-Headers: content-type
> 
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2 204 
< date: Mon, 10 Dec 2018 21:43:12 GMT
< set-cookie: __cfduid=d6441cd4692a567fe5a0a00ab4e00bda61544478191; expires=Tue, 10-Dec-19 21:43:11 GMT; path=/; domain=.tunnelnow-zzz.now.sh; HttpOnly
< _headers: [object Object]
< x-now-trace: bru1
< now: 1
< cache-control: s-maxage=0
< x-now-id: jgj07-1544478191832-flHq8titBKf717raqYBwNasI
< x-now-instance: 985420586
< expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
< server: cloudflare
< cf-ray: 4872e2ba4df52d8f-TXL
< 
* Connection #0 to host tunnelnow-zzz.now.sh left intact

As the result CORS is not working

Is this project maintained?

Hi, I'm wondering the active state of this project. Due now v1 is not supported anymore so tunnel.deploy is not working

I can make the changes needed to upgrade to now v2.

Gracefully handle the scenario when the user is on a OSS plan

With a OSS plan the tunnel.deploy command leads to this:

{ Error: Command failed: now deploy
> Error! Unexpected error. Please try again later. (
You are on the OSS plan. Your code and logs will be made public. If you agree with that, please run again with --public.)

https://tunnelnow-<random-string-here>.now.sh
    at Promise.all.then.arr (~/.nvm/versions/node/v8.2.1/lib/node_modules/tunnel.now/node_modules/execa/index.js:231:11)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
  code: 1,
  killed: false,
  stdout: 'https://tunnelnow-<random-string-here>.now.sh',
  stderr: '> Error! Unexpected error. Please try again later. (\nYou are on the OSS plan. Your code and logs will be made public. If you agree with that, please run again with --public.)\n',
  failed: true,
  signal: null,
  cmd: 'now deploy',
  timedOut: false }

The deployment happens successfully testing the URL.

add API

First, this is great.

I'd like to be able to consume this via an API in my own services. For example:

if ( process.env.NODE_ENV === 'dev' ) {
    const tunnelnow = require( 'tunnel.now' );

    const tunnel_info = await tunnelnow.tunnel( {
        port: 8000
    } );

    console.log( `got a tunnel at: ${ tunnel_info.url }` );

    // sometime later...

    tunnelnow.close( tunnel_info ); // removes this tunnel deployment
}

Any interest in this?
Would you accept a PR?
Any hints if I want to take a stab?

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.