/*
 * Stairs
 * Copyright 2017 (c) Mark van Renswoude
 *
 * https://git.x2software.net/pub/Stairs
*/
#include "./static.h"
#include "../debug.h"
#include "../assets/html.h"
#include "../assets/js.h"
#include "../assets/css.h"


void handleGzipped(AsyncWebServerRequest *request, const String& contentType, const uint8_t * content, size_t len)
{
  _d("HTTP :: static: "); _dln(request->url());
  AsyncWebServerResponse *response = request->beginResponse_P(200, contentType, content, len);
  response->addHeader("Content-Encoding", "gzip");
  request->send(response);
}


void registerStaticRoutes(AsyncWebServer* server)
{
  server->on("/", HTTP_GET, [](AsyncWebServerRequest *request) { handleGzipped(request, "text/html", EmbeddedIndex, sizeof(EmbeddedIndex)); });

  server->on("/bundle.js", HTTP_GET, [](AsyncWebServerRequest *request) { handleGzipped(request, "text/javascript", EmbeddedBundleJS, sizeof(EmbeddedBundleJS)); });
  server->on("/bundle.css", HTTP_GET, [](AsyncWebServerRequest *request) { handleGzipped(request, "text/css", EmbeddedBundleCSS, sizeof(EmbeddedBundleCSS)); });
}