-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae669e0
commit 2ed9bdc
Showing
4 changed files
with
153 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,4 @@ | |
.json.swp | ||
.yaml.swp | ||
.pem | ||
.iml | ||
.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
|