Skip to content

Commit

Permalink
Improved init-exec
Browse files Browse the repository at this point in the history
  • Loading branch information
trikko committed Dec 18, 2024
1 parent dcc98a1 commit 20b4fb8
Showing 1 changed file with 38 additions and 15 deletions.
53 changes: 38 additions & 15 deletions init-exec/source/app.d
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import std.path: buildPath;
import std.file: getcwd, mkdir, write;

immutable example =
`module app;
Expand All @@ -13,19 +10,19 @@ import serverino;
mixin ServerinoMain;
// If you need more than one endpoint, use @endpoint and (optionally) @priority
// See: https://github.com/trikko/serverino#defining-more-than-one-endpoint
// Use @endpoint and (optionally) @priority if you need more than one endpoint.
// More info: https://github.com/trikko/serverino#defining-more-than-one-endpoint
void example(Request request, Output output)
{
// Probably you want to delete this spam.
info("Hello, log! There's a new incoming request. Url: ", request.path);
info("Hello, log! There's a new incoming request. URL: ", request.path);
// Add the formatted HTML representation of the HTTP request to the output.
// Useful for debugging. Replace with your own HTML page.
output ~= request.dump(true);
}
/*
* Default configuration is used if you don't implement this function.
* See: https://trikko.github.io/serverino/serverino/config/ServerinoConfig.html
/* The default configuration is used if you do not implement this function.
@onServerInit ServerinoConfig configure()
{
Expand All @@ -34,17 +31,43 @@ void example(Request request, Output output)
.addListener("0.0.0.0", 8080)
.setMaxRequestTime(1.seconds)
.setMaxRequestSize(1024*1024); // 1 MB
// Many other options are available. Check the docs.
// Many other options are available.
// See: https://trikko.github.io/serverino/serverino/config/ServerinoConfig.html
}
*/
*/
`;

void main(string[] args)
int main(string[] args)
{
string sourceFolder = buildPath(getcwd(), "source");
mkdir(sourceFolder);
import std;

auto bold = "\033[1m";
auto reset = "\033[0m";
auto indent = repeat(" ", 13).join;

version(Windows)
{
bold = "";
reset = "";
}

writeln();

string sourceFolder = buildPath(getcwd(), "source");
string appFilePath = buildPath(sourceFolder, "app.d");
write(appFilePath, example);

if (exists(sourceFolder))
{
writeln(bold, "[ERROR]", reset, " A dub package already exists in the directory ", bold, getcwd(), reset, ".");
writeln(bold, "[ERROR]", reset, " Please choose an empty directory to initialize your new serverino app.");
return -1;
}

mkdir(sourceFolder);
std.file.write(appFilePath, example);
writeln(bold, indent, "Well done! Run your shiny new serverino app with:\n");
writeln(indent, "cd ", getcwd());
writeln(indent, "dub", reset, "\n");
return 0;
}

0 comments on commit 20b4fb8

Please sign in to comment.