title: Using Gradle serve a front end (JS) and a backend API (Java)
body: <p>Im trying to create a web application using Gradle. The front end UI will be built with Angular.js and the backend should be Java. When I say backend, I mean a Java / Spring based API that will be queried using Ajax from Angular.js.</p>
  
  <p>So basically what Im trying to do is to get any URL's that start with <code>mysite.com/api/...</code> should be routed to the <code>src/com/veight/client</code> files, or in other words to the Java backend. And then any other URLs such as <code>mysite.com/login</code> should be handled by the JavaScript / Angular.js front end. </p>
  
  <p>I have the JavaScript / Angular.js routing working for the front end using the following build.gradle file. How should I go about sending routes that match <code>mysite.com/api/...</code> to the Java / Spring back end?</p>
  
  <p>Thank you for the help! </p>
  
  <p>Note: I know that Java Spring naturally does this routing where it sends certain routes <code>mysite.com/home</code> to one folder and other routes <code>mysite.com/api/...</code> are handled buy a xml file. But I think its possible to handle this in the build.gradle file. So I was hoping to prove / disprove that theory. </p>
  
  <p>File Structure</p>
  
  <pre><code>.gradle
  .settings
  build
  gradle
  src
      com
          veight
              client
  WebContent
  </code></pre>
  
  <p>Heres my build.gradle:</p>
  
  <pre><code>buildscript {
      repositories {
          jcenter()
          mavenCentral()
      }
  
      dependencies {
          classpath 'org.gradle.api.plugins:gradle-tomcat-plugin:1.2.4' // Gradle Tomcat Plugin
          classpath 'com.eriwen:gradle-css-plugin:1.11.1'
          classpath 'com.eriwen:gradle-js-plugin:1.12.0'
      }
  }
  
  apply plugin: 'java'
  apply plugin: 'war'
  apply plugin: 'tomcat'
  apply plugin: 'eclipse-wtp'
  apply plugin: 'js'
  apply plugin: 'css'
  
  sourceCompatibility = 1.7
  version = '1.0'
  
  task wrapper(type: Wrapper) {
      gradleVersion = '2.0'
  }
  
  repositories {
      mavenCentral() // Allow access to the Maven Centeral Repo
  }
  
  dependencies {
      def tomcatVersion = '7.0.54'
      tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
              "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}"
      tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") {
          exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
      }
  }
  sourceSets {
      main {
          java {
              srcDirs 'src'
          }
      }
  }
  // End: Java Plugin Configuration
  
  // Start: Tomcat Plugin Configuration
  tomcatRun {
      httpPort = 8080
      stopPort = 8081
      URIEncoding = 'utf-8'
      webAppSourceDirectory = file('WebContent')
  }
  eclipse {
    wtp {
      component {
        contextPath = '/'
        deployName = 'client'
      }
    }
  }
  </code></pre>