Skip to content

Commit 97f228d

Browse files
committed
add a welcome screen
1 parent eabb9e7 commit 97f228d

File tree

8 files changed

+99
-5
lines changed

8 files changed

+99
-5
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
*.📦
2+
.DS_Store

Diff for: README.md

+15-3
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ The plan is to get to a feature set similar to Python frameworks like [Starlette
5252
<!-- GETTING STARTED -->
5353
## Getting Started
5454

55-
The only hard dependency for `lightbug_http` is Mojo.
56-
Learn how to set it up on the [Modular website](https://www.modular.com/max/mojo).
55+
The only hard dependencies for `lightbug_http` are Mojo and [Git](https://docs.github.com/en/get-started/getting-started-with-git).
56+
Learn how to get up and running with Mojo on the [Modular website](https://www.modular.com/max/mojo).
5757

58-
Once you have Mojo up and running on your local machine,
58+
Once you have Mojo set up locally,
5959

6060
1. Clone the repo
6161
```sh
@@ -64,6 +64,18 @@ Once you have Mojo up and running on your local machine,
6464
Alternatively, start the project in Github Codespaces for quick setup:
6565

6666
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/saviorand/lightbug_http)
67+
2. Switch to the project directory:
68+
```bash
69+
cd lightbug_http
70+
```
71+
then run:
72+
```bash
73+
mojo lightbug.🔥
74+
```
75+
76+
Open `localhost:8080` in your browser. You should see a welcome screen.
77+
78+
Congrats 🥳 You're using Lightbug!
6779
2. Add your handler in `lightbug.🔥` by passing a struct that satisfies the following trait:
6880
```mojo
6981
trait HTTPService:

Diff for: lightbug.🔥

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ from lightbug_http import *
33

44
fn main() raises:
55
var server = SysServer()
6-
let handler = Printer()
6+
let handler = Welcome()
77
server.listen_and_serve("0.0.0.0:8080", handler)

Diff for: lightbug_http/__init__.mojo

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from lightbug_http.http import HTTPRequest, HTTPResponse, OK
2-
from lightbug_http.service import HTTPService, Printer
2+
from lightbug_http.service import HTTPService, Welcome
33
from lightbug_http.sys.server import SysServer
44

55

Diff for: lightbug_http/http.mojo

+6
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,12 @@ fn OK(body: Bytes) -> HTTPResponse:
246246
)
247247

248248

249+
fn OK(body: Bytes, content_type: String) -> HTTPResponse:
250+
return HTTPResponse(
251+
ResponseHeader(200, String("OK")._buffer, content_type._buffer), body
252+
)
253+
254+
249255
fn encode(res: HTTPResponse) -> Bytes:
250256
var res_str = String()
251257
let protocol = strHttp11

Diff for: lightbug_http/service.mojo

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ struct Printer(HTTPService):
1717
return OK(body)
1818

1919

20+
@value
21+
struct Welcome(HTTPService):
22+
fn func(self, req: HTTPRequest) raises -> HTTPResponse:
23+
let html: String
24+
with open("static/lightbug_welcome.html", "r") as f:
25+
html = f.read()
26+
27+
return OK(html._buffer, "text/html")
28+
29+
2030
@value
2131
struct ExampleRouter(HTTPService):
2232
fn func(self, req: HTTPRequest) raises -> HTTPResponse:

Diff for: static/lightbug_welcome.html

+65
Large diffs are not rendered by default.

Diff for: static/logo.png

1.7 KB
Loading

0 commit comments

Comments
 (0)