mirror of
https://git.tesses.org/tesses50/crosslangextras.git
synced 2026-06-02 02:45:31 +00:00
Add the templates for npm
This commit is contained in:
37
Templates/npmwebapp/src/program.tcross
Normal file
37
Templates/npmwebapp/src/program.tcross
Normal file
@@ -0,0 +1,37 @@
|
||||
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();
|
||||
}
|
||||
Reference in New Issue
Block a user