Files
crosslangextras/Tesses.CrossLang.Shell/src/webapp.tcross
2025-12-23 16:54:07 -06:00

61 lines
1.5 KiB
Plaintext

func Tesses.CrossLang.Shell.WebApp(dd)
{
var dir = Env.CrossLangConfig / "WebApps";
if(dd.Arguments.Length == 1)
{
Console.WriteLine("List of web applications:");
Console.WriteLine("Use --port=PORT to set port");
if(FS.Local.DirectoryExists(dir))
each(var item : FS.Local.EnumeratePaths(dir))
{
Console.WriteLine(Tesses.CrossLang.GetNameAndDescription(item / item.GetFileName() + ".crvm"));
}
return 0;
}
else if(dd.Arguments.Length >= 2)
{
var webappname = dd.Arguments[1];
var webapppath = dir / webappname / webappname + ".crvm";
var port = 4206;
each(var item : dd.Options)
{
if(item.Key == "port")
{
var thePort = ParseLong(item.Value);
if(TypeOf(thePort) == "Long") port = thePort;
}
}
if(FS.Local.FileExists(webapppath))
{
const _dict = {};
const env = VM.CreateEnvironment(_dict);
env.RegisterEverything();
env.LockRegister();
_dict.Net ?? = {};
_dict.Net.WebServerPort = port;
env.LoadFileWithDependencies(FS.Local,webapppath);
var myArgs = [webapppath.ToString()];
for(var i = 2; i < dd.Arguments.Count; i++)
{
myArgs.Add(dd.Arguments[i]);
}
var res = env.GetDictionary().WebAppMain(myArgs);
Net.Http.ListenSimpleWithLoop(res, port);
res.Close();
return 0;
}
else {
Console.WriteLine($"Could not find web application with name {toolname}.");
return 1;
}
}
}