Files
crosslangextras/Templates/npmwebapp/src/program.tcross
2026-05-10 20:52:26 -05:00

37 lines
829 B
Plaintext

class MyWebApp {
private fileServer;
private mountable;
private pages;
public MyWebApp()
{
this.fileServer = new FileServer(embeddir("/"), true, false);
this.mountable = new MountableServer((ctx)=>{
const page = this.pages.[ctx.Path];
if(TypeIsDefined(page)) return page(ctx);
return false;
});
this.mountable.Mount("/dist/",this.fileServer);
this.pages = {
.["/"] = Pages.Index,
.["/counter"] = Pages.Counter,
.["/about"] = Pages.About,
.["/echo"] = Pages.Echo
};
}
public Handle(ctx)
{
return this.mountable.Handle(ctx);
}
public Close()
{
this.mountable = null;
}
}
func WebAppMain(args)
{
return new MyWebApp();
}