changeset 2005:fe45d2c967f1

set_https only in init.luan
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 28 Jul 2025 15:41:29 -0600
parents 2936d52d9d5b
children b10031b477a4
files src/luan/host/https.luan src/luan/modules/http/LuanHandler.java
diffstat 2 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/host/https.luan	Sun Jul 27 16:23:36 2025 -0600
+++ b/src/luan/host/https.luan	Mon Jul 28 15:41:29 2025 -0600
@@ -1,5 +1,6 @@
 local Luan = require "luan:Luan.luan"
 local error = Luan.error
+local new_error = Luan.new_error or error()
 local load_file = Luan.load_file or error()
 local ipairs = Luan.ipairs or error()
 local Boot = require "luan:Boot.luan"
@@ -111,6 +112,10 @@
 
 
 function Hosted.set_https(is_https)
+	if Http.did_init() then
+		logger.error(new_error("set_https called outside of init.luan"))
+		return
+	end
 	local domain = Http.domain
 	local dir = uri("site:").parent()
 	local nginx_file = dir.child("nginx.ssl.conf")
--- a/src/luan/modules/http/LuanHandler.java	Sun Jul 27 16:23:36 2025 -0600
+++ b/src/luan/modules/http/LuanHandler.java	Mon Jul 28 15:41:29 2025 -0600
@@ -47,6 +47,7 @@
 	private static final Method disableLuanMethod;
 	private static final Method testAsInitMethod;
 	private static final Method linkToDomainMethod;
+	private static final Method didInitMethod;
 	static {
 		try {
 			resetLuanMethod = LuanHandler.Fns.class.getMethod( "reset_luan" );
@@ -54,6 +55,7 @@
 			disableLuanMethod = LuanHandler.Fns.class.getMethod( "disable_luan" );
 			testAsInitMethod = LuanHandler.Fns.class.getMethod( "test_as_init", String.class, String.class );
 			linkToDomainMethod = LuanHandler.Fns.class.getMethod( "link_to_domain", String.class );
+			didInitMethod = LuanHandler.Fns.class.getMethod( "did_init" );
 		} catch(NoSuchMethodException e) {
 			throw new RuntimeException(e);
 		}
@@ -71,6 +73,7 @@
 			Http.put( luanInit, "disable_luan", new LuanJavaFunction(disableLuanMethod,fns) );
 			Http.put( luanInit, "test_as_init", new LuanJavaFunction(testAsInitMethod,fns) );
 			Http.put( luanInit, "link_to_domain", new LuanJavaFunction(linkToDomainMethod,fns) );
+			Http.put( luanInit, "did_init", new LuanJavaFunction(didInitMethod,fns) );
 		} catch(LuanException e) {
 			throw new RuntimeException(e);
 		}
@@ -231,6 +234,10 @@
 		this.domain = domain;
 	}
 
+	private boolean did_init() {
+		return didInit;
+	}
+
 	public static final class Fns implements ThreadLuan.Closeables {
 		private final Reference<LuanHandler> ref;
 
@@ -271,6 +278,10 @@
 		public void link_to_domain(String domain) throws LuanException {
 			lh().link_to_domain(domain);
 		}
+
+		public boolean did_init() throws LuanException {
+			return lh().did_init();
+		}
 	}