From e545e292871f30e572bd9ae0a04fc44899c4e77d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?= =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?= Date: Wed, 21 Sep 2022 10:36:40 +0800 Subject: Now how index is built, can be determined here --- configure.ac | 2 ++ main.c | 29 ++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index d9745c3..a37935d 100644 --- a/configure.ac +++ b/configure.ac @@ -2,6 +2,8 @@ AC_INIT([shopify-app-template-c], [0.0], [prabowo@darapsa.org]) AM_INIT_AUTOMAKE([-Wall -Werror foreign]) AC_PROG_CC PKG_CHECK_MODULES([DEPS], [libmicrohttpd libgcrypt gnutls libpcre2-8 libcurl json-c]) +AC_CHECK_HEADERS([fcntl.h unistd.h]) +AC_FUNC_MALLOC AC_TYPE_SIZE_T AC_CONFIG_FILES([Makefile]) AC_OUTPUT diff --git a/main.c b/main.c index 97be7a1..f4e9a40 100644 --- a/main.c +++ b/main.c @@ -1,21 +1,40 @@ -#include #include +#include +#include +#include +#include +#include #include +static char *html(const char *host) +{ + static const char *path_rel = "/frontend/index.html"; + char path[strlen(APP_DIR) + strlen(path_rel) + 1]; + sprintf(path, "%s%s", APP_DIR, path_rel); + int fd = open(path, O_RDONLY); + struct stat sb; + fstat(fd, &sb); + char template[sb.st_size + 1]; + read(fd, path, sb.st_size); + close(fd); + const size_t html_len = sb.st_size - strlen("%s") * 4 + strlen(API_KEY) + + strlen(host) + strlen(APP_URL) * 2; + char *html = malloc(html_len + 1); + sprintf(html, template, API_KEY, host, APP_URL, APP_URL); + return html; +} + int main(int argc, char *argv[]) { const size_t app_dir_len = strlen(APP_DIR); static const char *scopes_rel = "/shopify.app.toml"; char scopes[app_dir_len + strlen(scopes_rel) + 1]; sprintf(scopes, "%s%s", APP_DIR, scopes_rel); - static const char *index_rel = "/frontend/index.html"; - char index[app_dir_len + strlen(index_rel) + 1]; - sprintf(index, "%s%s", APP_DIR, index_rel); static const char *js_dir_rel = "/frontend/build"; char js_dir[app_dir_len + strlen(js_dir_rel) + 1]; sprintf(js_dir, "%s%s", APP_DIR, js_dir_rel); shopify_app(API_KEY, API_SECRET_KEY, APP_URL, "/auth", APP_ID, scopes, - index, js_dir, (struct shopify_api[]){ + html, js_dir, (struct shopify_api[]){ { "/products", "GET", -- cgit v1.2.3