mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-27 00:38:11 -07:00
Fix the server response.
This commit is contained in:
parent
48d9173790
commit
29e26a6748
1 changed files with 26 additions and 19 deletions
|
@ -4,6 +4,7 @@ import com.beust.kobalt.Args
|
||||||
import com.beust.kobalt.api.Kobalt
|
import com.beust.kobalt.api.Kobalt
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
|
import spark.ResponseTransformer
|
||||||
import spark.Route
|
import spark.Route
|
||||||
import spark.Spark
|
import spark.Spark
|
||||||
|
|
||||||
|
@ -20,30 +21,36 @@ class SparkServer(val initCallback: (String) -> List<Project>, val cleanUpCallba
|
||||||
SparkServer.cleanUpCallback = cleanUpCallback
|
SparkServer.cleanUpCallback = cleanUpCallback
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class JsonTransformer : ResponseTransformer {
|
||||||
|
val gson = Gson()
|
||||||
|
override fun render(model: Any) = gson.toJson(model)
|
||||||
|
}
|
||||||
|
|
||||||
override fun run(port: Int) {
|
override fun run(port: Int) {
|
||||||
Spark.port(port)
|
Spark.port(port)
|
||||||
Spark.get("/hello", Route { req, res -> "Hello world" })
|
Spark.get("/hello", { req, res -> "Hello world" })
|
||||||
Spark.get("/v0/getDependencies", { request, response ->
|
Spark.get("/v0/getDependencies", "application/json", Route { request, response ->
|
||||||
val buildFile = request.queryParams("buildFile")
|
val buildFile = request.queryParams("buildFile")
|
||||||
if (buildFile != null) {
|
initCallback(buildFile)
|
||||||
val projects = initCallback(buildFile)
|
val result =
|
||||||
val result = try {
|
if (buildFile != null) {
|
||||||
val dependencyData = Kobalt.INJECTOR.getInstance(DependencyData::class.java)
|
initCallback(buildFile)
|
||||||
val args = Kobalt.INJECTOR.getInstance(Args::class.java)
|
try {
|
||||||
|
val dependencyData = Kobalt.INJECTOR.getInstance(DependencyData::class.java)
|
||||||
|
val args = Kobalt.INJECTOR.getInstance(Args::class.java)
|
||||||
|
|
||||||
val dd = dependencyData.dependenciesDataFor(buildFile, args)
|
dependencyData.dependenciesDataFor(buildFile, args)
|
||||||
Gson().toJson(dd)
|
} catch(ex: Exception) {
|
||||||
} catch(ex: Exception) {
|
"Error: " + ex.message
|
||||||
"Error: " + ex.message
|
} finally {
|
||||||
} finally {
|
cleanUpCallback()
|
||||||
cleanUpCallback()
|
}
|
||||||
|
} else {
|
||||||
|
"error"
|
||||||
}
|
}
|
||||||
|
cleanUpCallback()
|
||||||
result
|
result
|
||||||
} else {
|
}, JsonTransformer())
|
||||||
"error"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue