summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2022-09-14 19:00:54 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2022-09-14 19:00:54 +0800
commit092ab36bc4c2ecdce80082e51386d01cc2d47305 (patch)
treea1fbf5999acab4a137bb25b4569a5befb3f256c9
Minimum to get an app running
The config and HTML files are in this project, so the paths shouldn't be decided in libshopify.
-rw-r--r--.gitignore14
-rw-r--r--shopify.app.toml3
-rw-r--r--web/Makefile.am4
-rw-r--r--web/configure.ac8
-rw-r--r--web/frontend/index.html9
-rw-r--r--web/main.c42
6 files changed, 80 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3ba74ef
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,14 @@
+*~
+*.swp
+Makefile.in
+aclocal.m4
+autom4te.cache
+autoscan*.log
+build
+compile
+config.*
+configure
+configure.scan
+depcomp
+install-sh
+missing
diff --git a/shopify.app.toml b/shopify.app.toml
new file mode 100644
index 0000000..7659888
--- /dev/null
+++ b/shopify.app.toml
@@ -0,0 +1,3 @@
+# This file stores configurations for your Shopify app.
+
+scopes = "write_products"
diff --git a/web/Makefile.am b/web/Makefile.am
new file mode 100644
index 0000000..310bd37
--- /dev/null
+++ b/web/Makefile.am
@@ -0,0 +1,4 @@
+bin_PROGRAMS = shopifyappd
+shopifyappd_SOURCES = main.c
+shopifyappd_CPPFLAGS = $(DEPS_CFLAGS)
+shopifyappd_LDFLAGS = $(DEPS_LIBS) -ltoml -lshopify
diff --git a/web/configure.ac b/web/configure.ac
new file mode 100644
index 0000000..7ef439c
--- /dev/null
+++ b/web/configure.ac
@@ -0,0 +1,8 @@
+AC_INIT([shopify-app-template-c], [0.0], [erik@darapsa.co.id])
+AM_INIT_AUTOMAKE([-Wall -Werror foreign])
+AC_PROG_CC
+PKG_CHECK_MODULES([DEPS], [libmicrohttpd libgcrypt gnutls libpcre2-8 libcurl json-c])
+AC_FUNC_MALLOC
+AC_TYPE_SIZE_T
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
diff --git a/web/frontend/index.html b/web/frontend/index.html
new file mode 100644
index 0000000..b6b3f23
--- /dev/null
+++ b/web/frontend/index.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html lang=en>
+ <head>
+ <meta charset=utf-8/>
+ </head>
+ <body>
+ Hello from C!
+ </body>
+</html>
diff --git a/web/main.c b/web/main.c
new file mode 100644
index 0000000..83a50aa
--- /dev/null
+++ b/web/main.c
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "shopify.h"
+
+static enum MHD_Result handle_request(void *cls, struct MHD_Connection *conn,
+ const char *url, const char *method, const char *version,
+ const char *upload_data, size_t *upload_data_size,
+ void **con_cls)
+{
+ if (strcmp(method, "GET"))
+ return MHD_NO;
+ struct shopify_param *params = *con_cls;
+ if (!params) {
+ params = malloc(sizeof(struct shopify_param));
+ *con_cls = params;
+ return MHD_YES;
+ }
+ static const char *redir_url = "/auth";
+ if (!shopify_valid(conn, url, redir_url, API_SECRET_KEY, &params)) {
+ free(params);
+ return MHD_NO;
+ }
+ struct MHD_Response *resp;
+ enum MHD_Result ret = shopify_respond(params, url, redir_url, APP_URL,
+ APP_ID, API_KEY, API_SECRET_KEY, APP_DIR, conn, &resp);
+ MHD_destroy_response(resp);
+ free(params);
+ return ret;
+}
+
+int main(int argc, char *argv[])
+{
+ shopify_init();
+ struct MHD_Daemon *daemon
+ = MHD_start_daemon(MHD_USE_INTERNAL_POLLING_THREAD, 3000, NULL,
+ NULL, &handle_request, NULL, MHD_OPTION_END);
+ getchar();
+ MHD_stop_daemon(daemon);
+ shopify_cleanup();
+ return 0;
+}