diff options
author | Christian Grothoff <christian@grothoff.org> | 2024-08-23 09:28:05 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2024-08-23 09:28:05 +0200 |
commit | 203719c7a0ddfb326984e0cf1a71d3961fab514e (patch) | |
tree | 57afc57ea3a24920676b766613fd5e1aa15d0674 /src | |
parent | 5fcddeed9bef716475a7b46a4a6180f32812ca14 (diff) |
add logic to serve SPA
Diffstat (limited to 'src')
-rw-r--r-- | src/auditor/Makefile.am | 1 | ||||
-rw-r--r-- | src/auditor/taler-auditor-httpd.c | 16 | ||||
-rw-r--r-- | src/auditor/taler-auditor-httpd.h | 1 | ||||
-rw-r--r-- | src/auditor/taler-auditor-httpd_spa.c | 78 | ||||
-rw-r--r-- | src/auditor/taler-auditor-httpd_spa.h | 58 |
5 files changed, 151 insertions, 3 deletions
diff --git a/src/auditor/Makefile.am b/src/auditor/Makefile.am index ab25b30f3..622794b78 100644 --- a/src/auditor/Makefile.am +++ b/src/auditor/Makefile.am @@ -179,6 +179,7 @@ taler_helper_auditor_wire_debit_LDADD = \ taler_auditor_httpd_SOURCES = \ taler-auditor-httpd.c taler-auditor-httpd.h \ + taler-auditor-httpd_spa.c taler-auditor-httpd_spa.h \ taler-auditor-httpd_deposit-confirmation.c taler-auditor-httpd_deposit-confirmation.h \ taler-auditor-httpd_deposit-confirmation-get.c taler-auditor-httpd_deposit-confirmation-get.h \ taler-auditor-httpd_deposit-confirmation-del.c taler-auditor-httpd_deposit-confirmation-del.h \ diff --git a/src/auditor/taler-auditor-httpd.c b/src/auditor/taler-auditor-httpd.c index bda028faf..372d3106b 100644 --- a/src/auditor/taler-auditor-httpd.c +++ b/src/auditor/taler-auditor-httpd.c @@ -30,6 +30,7 @@ #include "taler_mhd_lib.h" #include "taler_auditordb_lib.h" #include "taler_exchangedb_lib.h" +#include "taler-auditor-httpd_spa.h" #include "taler-auditor-httpd_deposit-confirmation.h" #include "taler-auditor-httpd_deposit-confirmation-del.h" #include "taler-auditor-httpd_deposit-confirmation-get.h" @@ -406,8 +407,12 @@ handle_mhd_request (void *cls, .method = MHD_HTTP_METHOD_PUT, .mime_type = "application/json", .handler = &TAH_DEPOSIT_CONFIRMATION_handler, - .response_code = MHD_HTTP_OK, - .requires_auth = true + .response_code = MHD_HTTP_OK + }, + { + .url = "/spa/", + .method = MHD_HTTP_METHOD_GET, + .handler = &TAH_spa_handler }, { "/monitoring/deposit-confirmation", @@ -1140,6 +1145,13 @@ run (void *cls, GNUNET_SCHEDULER_shutdown (); return; } + if (GNUNET_OK != + TAH_spa_init ()) + { + global_ret = EXIT_NOTCONFIGURED; + GNUNET_SCHEDULER_shutdown (); + return; + } TEAH_DEPOSIT_CONFIRMATION_init (); fh = TALER_MHD_bind (cfg, "auditor", diff --git a/src/auditor/taler-auditor-httpd.h b/src/auditor/taler-auditor-httpd.h index 374963cca..3480508aa 100644 --- a/src/auditor/taler-auditor-httpd.h +++ b/src/auditor/taler-auditor-httpd.h @@ -84,7 +84,6 @@ struct TAH_RequestHandler * Function to call to handle the request. * * @param rh this struct - * @param mime_type the @e mime_type for the reply (hint, can be NULL) * @param connection the MHD connection to handle * @param[in,out] connection_cls the connection's closure (can be updated) * @param upload_data upload data diff --git a/src/auditor/taler-auditor-httpd_spa.c b/src/auditor/taler-auditor-httpd_spa.c new file mode 100644 index 000000000..fa9a5a540 --- /dev/null +++ b/src/auditor/taler-auditor-httpd_spa.c @@ -0,0 +1,78 @@ +/* + This file is part of TALER + Copyright (C) 2020, 2023, 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of EXCHANGEABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +*/ +/** + * @file taler-auditor-httpd_spa.c + * @brief logic to load single page app (/spa) + * @author Christian Grothoff + */ +#include "platform.h" +#include <gnunet/gnunet_util_lib.h> +#include "taler_util.h" +#include "taler_mhd_lib.h" +#include <gnunet/gnunet_mhd_compat.h> +#include "taler-auditor-httpd_spa.h" + + +/** + * Resources of the auditor SPA. + */ +static struct TALER_MHD_Spa *spa; + + +MHD_RESULT +TAH_spa_handler ( + /* const */ struct TAH_RequestHandler *rh, + struct MHD_Connection *connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]) +{ + const char *path = args[0]; + + if (NULL == path) + path = "index.html"; + return TALER_MHD_spa_handler (spa, + connection, + path); +} + + +enum GNUNET_GenericReturnValue +TAH_spa_init () +{ + spa = TALER_MHD_spa_load ("auditor/spa/"); + if (NULL == spa) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + return GNUNET_OK; +} + + +/** + * Nicely shut down. + */ +void __attribute__ ((destructor)) +get_spa_fini () +{ + if (NULL != spa) + { + TALER_MHD_spa_free (spa); + spa = NULL; + } +} diff --git a/src/auditor/taler-auditor-httpd_spa.h b/src/auditor/taler-auditor-httpd_spa.h new file mode 100644 index 000000000..5734c29fa --- /dev/null +++ b/src/auditor/taler-auditor-httpd_spa.h @@ -0,0 +1,58 @@ +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of EXCHANGEABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +*/ +/** + * @file taler-auditor-httpd_spa.h + * @brief logic to preload and serve static files + * @author Christian Grothoff + */ +#ifndef TALER_AUDITOR_HTTPD_SPA_H +#define TALER_AUDITOR_HTTPD_SPA_H + +#include <microhttpd.h> +#include "taler-auditor-httpd.h" + + +/** + * Return our single-page-app user interface + * for staff (see contrib/wallet-core/). + * + * @param rh request context + * @param connection the MHD connection to handle + * @param[in,out] connection_cls the connection's closure (can be updated) + * @param upload_data upload data + * @param[in,out] upload_data_size number of bytes (left) in @a upload_data + * @return MHD result code + */ +MHD_RESULT +TAH_spa_handler ( + /* const */ struct TAH_RequestHandler *rh, + struct MHD_Connection *connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + const char *const args[]); + + +/** + * Preload and compress SPA files. + * + * @return #GNUNET_OK on success + */ +enum GNUNET_GenericReturnValue +TAH_spa_init (void); + + +#endif |