title: Connection problems between two Google compute engine instances
body: <p>I'm working on a webapp with Go and Javascript. I also use Google Compute Engine for serving my app. I have 3 VMs, one for my DB, on for the frontend and the last for the backend. I don't have any problem to recover datas from my DB with Go but when I'm try to send datas from Go to Javascript, I got this error message </p>
  
  <pre><code>GET http://10.132.0.3/ 0 ()    (index):10
      callGoServer    @   (index):10
      onclick @   (index):15
  
  Uncaught (in promise) TypeError: Failed to fetch    (index):1 
      Promise.then (async)        
      callGoServer    @   (index):12
      onclick @   (index):15
  </code></pre>
  
  <p>Here's my Go code</p>
  
  <pre><code>package main
  
  import (
      "database/sql"
      "encoding/json"
      "fmt"
      "github.com/gorilla/handlers"
      "github.com/gorilla/mux"
      "log"
      "net/http"
  
      _ "github.com/lib/pq"
  )
  
  //Quote is a quote
  type Quote struct {
      ID     int `json:"id"`
      Phrase string `json:"phrase"`
      Author string `json:"author"`
  }
  
  var db *sql.DB
  
  func init() {
      var err error
      db, err = sql.Open("postgres", "postgres://postgres:password@10.132.0.2:5432/quotes?sslmode=disable")
      if err != nil {
          panic(err)
      }
  
      if err = db.Ping(); err != nil {
          panic(err)
      }
      fmt.Println("You connected to your database")
  }
  
  func getQuotes(w http.ResponseWriter, r *http.Request) {
  
      if r.Method != "GET" {
          http.Error(w, http.StatusText(405), http.StatusMethodNotAllowed)
          return
      }
  
      rows, err := db.Query("SELECT id, phrase, author FROM citations ORDER BY RANDOM() LIMIT 1;")
      if err != nil {
          http.Error(w, http.StatusText(500), 500)
          return
      }
      defer rows.Close()
  
      quotations := make([]Quote, 0)
      for rows.Next() {
          qt := Quote{}
          err := rows.Scan(&amp;qt.ID, &amp;qt.Phrase, &amp;qt.Author)
          if err != nil {
              panic(err)
          }
          quotations = append(quotations, qt)
      }
      if err = rows.Err(); err != nil {
          panic(err)
      }
  
      for _, qt := range quotations {
          payload, _ := json.Marshal(qt)
          w.Header().Add("Content-Type", "application/json")
          w.Write(payload)
      }
  }
  
  func main() {
      router:= mux.NewRouter()
      router.HandleFunc("/", getQuotes)
      log.Fatal(http.ListenAndServe(":8080",handlers.CORS(handlers.AllowedHeaders([]string{"X-Requested-With", "Content-Type", "Authorization"}),handlers.AllowedMethods([]string{"GET","POST","PUT","DELETE"}),handlers.AllowedOrigins([]string{"*"}))(router)))
  }
  </code></pre>
  
  <p>Here's my JS code</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
      &lt;head&gt;
          &lt;meta charset="UTF-8"&gt;
          &lt;title&gt;Random quote&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;script type="text/javascript" language="javascript"&gt;
              function callGoServer(){
                  fetch('http://10.132.0.3')
                      .then(response =&gt; response.json())
                      .then(json =&gt; console.log(json))
              }
          &lt;/script&gt;
          &lt;button onclick="callGoServer()"&gt;Click here&lt;/button&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I've made a firewall rule on GCP that allow TCP protocol between my VM via port <code>5432</code> (postgresql) and <code>8080</code> (my go server)</p>
  
  <p>Does someone can help me ?</p>
  
  <p>Thanks</p>