First commit
All checks were successful
Build tesses.net / build-and-push-image (push) Successful in 49s
All checks were successful
Build tesses.net / build-and-push-image (push) Successful in 49s
This commit is contained in:
41
src/program.tcross
Normal file
41
src/program.tcross
Normal file
@@ -0,0 +1,41 @@
|
||||
|
||||
var pages = {
|
||||
.["/"] = SendText("text/html",(ctx)=>Pages.Index()),
|
||||
.["/cross-image"] = SendText("text/html",(ctx)=>Pages.CrossImage()),
|
||||
.["/apps"] = SendText("text/html",(ctx)=>Pages.MyApps()),
|
||||
.["/othersites"] = SendText("text/html",(ctx)=>Pages.OtherSites()),
|
||||
.["/css/styles-new.css"] = SendBytes("styles-new.css",embed("css/styles-new.css")),
|
||||
.["/img/favicon.svg"] = SendBytes("favicon.svg",embed("img/favicon.svg")),
|
||||
.["/img/jesus.svg"] = SendBytes("jesus.svg",embed("img/jesus.svg")),
|
||||
.["/robots.txt"] = SendText("text/plain",(ctx)=>"User-Agent: *\r\nAllow: /\r\n"),
|
||||
.["/favicon.ico"] = SendBytes("favicon.ico",embed("favicon.ico"))
|
||||
};
|
||||
func SendBytes(filename,data)
|
||||
{
|
||||
return (ctx)=>{
|
||||
ctx.WithMimeType(Net.Http.MimeType(filename)).SendBytes(data);
|
||||
};
|
||||
}
|
||||
|
||||
func SendText(mimeType,cb)
|
||||
{
|
||||
return (ctx)=>{
|
||||
|
||||
const text = cb(ctx);
|
||||
ctx.WithMimeType(mimeType).SendText(text);
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
func main(args)
|
||||
{
|
||||
Net.Http.ListenSimpleWithLoop((ctx)=>{
|
||||
if(pages.[ctx.Path](ctx) ?? false)
|
||||
return true;
|
||||
else {
|
||||
ctx.StatusCode = 404;
|
||||
ctx.WithMimeType("text/html").SendText(Components.Shell($"File {ctx.Path} Not Found",<h1>:( Page {ctx.Path} not found</h1>));
|
||||
return true;
|
||||
}
|
||||
},4206);
|
||||
}
|
||||
Reference in New Issue
Block a user