diff --git a/.dockerignore b/.dockerignore index 1058f53..2a88172 100644 --- a/.dockerignore +++ b/.dockerignore @@ -25,6 +25,8 @@ **/logs **/.DS_Store !**/project/assembly.sbt +!**/web/dist/index.html +!**/web/dist/bundle.js # flyctl launch added from .idea/.gitignore # Default ignored files diff --git a/Dockerfile b/Dockerfile index 8d39ab4..a95cd05 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM amazoncorretto:17-alpine -COPY ./web /web +COPY ./web/dist/bundle.js ./web/dist/index.html /web/dist/ COPY ./target/scala-2.13/WeatherTool-assembly-0.1.1-SNAPSHOT.jar /app.jar VOLUME /data diff --git a/src/main/scala/fetch/FetchService.scala b/src/main/scala/fetch/FetchService.scala index e39ac2a..5a26348 100644 --- a/src/main/scala/fetch/FetchService.scala +++ b/src/main/scala/fetch/FetchService.scala @@ -49,7 +49,6 @@ object FetchService { } def fetchSingleFile(fileName: String): IO[(String, String)] = { - println("start fetching") fetchFiles(List(fileName)).flatMap { results => results.headOption match { case Some(Right(result)) => IO.pure(result) diff --git a/src/main/scala/server/Server.scala b/src/main/scala/server/Server.scala index c29f6c6..4ac5860 100644 --- a/src/main/scala/server/Server.scala +++ b/src/main/scala/server/Server.scala @@ -9,12 +9,13 @@ import server.ValidateRoutes.{AggKey, CityList, DateTimeRange, ValidDate} import io.circe.{Json, Printer} import org.http4s._ import org.http4s.dsl.io._ -import org.http4s.server.Router +import org.http4s.server.{Router, staticcontent} import org.http4s.server.blaze.BlazeServerBuilder import io.circe.syntax._ import parse.Aggregate.AggregateValueImplicits.aggregateValueEncoder import parse.Aggregate.{AggregateKey, UserQuery} import fs2.Stream +import org.http4s.server.staticcontent.FileService object Server { @@ -27,15 +28,15 @@ object Server { } } - private val appRoutes = HttpRoutes.of[IO] { + private val apiRoutes = HttpRoutes.of[IO] { - // http://localhost:3000/query/20230414_2200-20230501_1230/Liepāja,Rēzekne/tempMax/max + // http://0.0.0.0:8080/api/query/20230414_2200-20230501_1230/Liepāja,Rēzekne/tempMax/max case GET -> Root / "query" / DateTimeRange(from, to) / CityList(cities) / field / AggKey(key) => DBService.getInRange(from, to) .map(Parser.queryData(UserQuery(cities, field, key), _)) .flatMap(result => Ok(result.asJson.pretty)) - // http://localhost:3000/fetch/date/20230423 + // http://0.0.0.0:8080/api/fetch/date/20230423 case GET -> Root / "fetch" / "date" / ValidDate(date) => val result = for { fetchResultEither <- FetchService.fetchFromDate(date).attempt @@ -57,33 +58,38 @@ object Server { ).pretty) } - // http://localhost:3000/show/all_dates + // http://0.0.0.0:8080/api/show/all_dates case GET -> Root / "show" / "all_dates" => DBService.getDates().flatMap(dates => Ok(dates.asJson.pretty) ) - // http://localhost:3000/show/date/20230423 + // http://0.0.0.0:8080/api/show/date/20230423 case GET -> Root / "show" / "date" / ValidDate(date) => DBService.getDateFileNames(date).flatMap(fileNames => Ok(fileNames.asJson.pretty) ) - // http://localhost:3000/help - case GET -> Root / "help" => + // http://0.0.0.0:8080/api/help + case GET -> Root / "help" => { + val host = "weather-tool.fly.dev" Ok(Json.obj( "aggregate fields" -> WeatherData.getKeys.asJson, "aggregate keys" -> AggregateKey.getKeys.asJson, "example urls" -> List( - "http://localhost:3000/query/20230414_2200-20230501_1230/Liepāja,Rēzekne/tempMax/max", - "http://localhost:3000/fetch/date/20230423", - "http://localhost:3000/show/all_dates", - "http://localhost:3000/show/date/20230423", + s"https://$host/api/query/20230414_2200-20230501_1230/Liepāja,Rēzekne/tempMax/max", + s"https://$host/api/fetch/date/20230423", + s"https://$host/api/show/all_dates", + s"https://$host/api/show/date/20230423", ).asJson, ).pretty) + } } - private val httpApp = Router("/" -> appRoutes).orNotFound + private val httpApp = Router( + "/" -> staticcontent.fileService[IO](FileService.Config("./web/dist")), + "/api" -> apiRoutes + ).orNotFound def run: Stream[IO, ExitCode] = BlazeServerBuilder[IO] diff --git a/web/dist/bundle.js b/web/dist/bundle.js new file mode 100644 index 0000000..b6ee185 --- /dev/null +++ b/web/dist/bundle.js @@ -0,0 +1,3 @@ +window.onload = () => { + console.log("this comes from bundle.js") +} \ No newline at end of file diff --git a/web/index.html b/web/dist/index.html similarity index 55% rename from web/index.html rename to web/dist/index.html index c37fb73..ec4400a 100644 --- a/web/index.html +++ b/web/dist/index.html @@ -5,6 +5,8 @@