Skip to content

Commit

Permalink
server side wip
Browse files Browse the repository at this point in the history
  • Loading branch information
librasteve committed Aug 12, 2024
1 parent ae669e0 commit 2ed9bdc
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
.json.swp
.yaml.swp
.pem
.iml
.iml
43 changes: 43 additions & 0 deletions bin/server.raku
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env raku
use v6.d;

use Cro::HTTP::Router;
use Cro::HTTP::Server;
use Cro::HTTP::Log;

my $dynamic-routes-supply = Supply.new;

sub create-router {
my @dynamic-routes;
$dynamic-routes-supply.tap(-> $route { @dynamic-routes.push($route) });

route {
get -> 'hello' {
content 'text/plain', 'Hello, World!';
}
for @dynamic-routes -> $route {
get -> $route.path {
content 'text/plain', $route.response;
}
}
}
}

my $router = create-router();

my $server = Cro::HTTP::Server.new:
:host<localhost>,
:port(10000),
:$router;

$server.start;

# Example of adding a dynamic route
$dynamic-routes-supply.emit({ path => 'dynamic', response => 'This is a dynamic route' });

react whenever signal(SIGINT) {
$server.stop;
exit;
}

# $dynamic-routes-supply.emit({ path => 'dynamic', response => 'This is a dynamic route' }).
12 changes: 12 additions & 0 deletions bin/watch.raku
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use IO::Notification::Recursive;

my $dir = "."; # Directory to watch
my $supply = watch-recursive($dir, :update);

$supply.tap(-> $change {
say "Change detected: $change";
# Handle the change here
});

# Keep the program running
loop { }
97 changes: 97 additions & 0 deletions stash.rakumod
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
use v6.d;

my $page = Page.new:
Html => Html.new:
Head => Head.new:
Meta => [
Meta.new: m1,
Meta.new: m2
],
Title => Title.new:

class Meta {
has $.name;
has $.content;

method render {
'<meta name="' ~ $!name ~ '" content="' ~ $!content ~ '">' ~ "\n"
}
}

class Title {
has $.title;

method render {
'<title>' ~ $!title ~ '</title>' ~ "\n"
}
}

class Script {
has $.src;

method render {
'<script src="' ~ $!src ~ '"></script>' ~ "\n"
}
}

class Link {
has $.rel;
has $.href;

method render {
'<link rel="' ~ $!rel ~ '" href="' ~ $!href ~ '">' ~ "\n"
}
}

class Style {
has $.css;

method render {
"$!css\n"
}
}

class Head {
has Meta @.metas;
has Title $.title;
has Script @.scripts;
has Link @.links;
has Style $.style;

method render {
{ .render for @!metas } ~ "\n" ~
$!title.render ~ "\n" ~
{ .render for @!scripts } ~ "\n" ~
{ .render for @!links } ~ "\n" ~
$!style.render ~ "\n"
}
}

class Body {
has $.text;

method render {
"$!text\n"
}
}

class Html {
has Head $.head;
has Body $.body;

method render {
$!head.render ~ "\n" ~
$!body.render ~ "\n"
}
}

class Page {
has $.doctype = 'html';
has Html $.html;

method render {
"<!doctype $!doctype>\n" ~
$!html.render ~ "\n"
}
}

0 comments on commit 2ed9bdc

Please sign in to comment.