Skip to content

Commit eaa9fb4

Browse files
committed
Let There Be Web Systems (190 tests)
1 parent db646e6 commit eaa9fb4

32 files changed

+1541
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
- DevSystem, Liza::DevBox, Liza::Command, AppCommand, and others
1010
- HappySystem, Liza::HappyBox, Liza::Axo, Axo, and others
1111
- NetSystem, Liza::NetBox, Liza::Adapter, Liza::Database, Liza::Model, AppModel, and others
12+
- WebSystem, Liza::WebBox, Liza::Request, AppRequest, and others

Gemfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,10 @@ group :net do
1818
gem "redis", "~> 5.0"
1919
gem "sqlite3", "~> 1.5"
2020
end
21+
22+
group :web do
23+
# gems you only want to load if WebSystem is loaded
24+
gem "rack", "~> 3.0"
25+
gem "rackup", "~> 0.2.2"
26+
gem "puma", "~> 5.6"
27+
end

Gemfile.lock

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,30 @@ GEM
1212
colorize (0.8.1)
1313
connection_pool (2.3.0)
1414
dotenv (2.8.1)
15+
nio4r (2.5.8)
16+
puma (5.6.5)
17+
nio4r (~> 2.0)
18+
rack (3.0.0)
19+
rackup (0.2.2)
20+
rack (>= 3.0.0.beta1)
21+
webrick
1522
rake (13.0.6)
1623
redis (5.0.5)
1724
redis-client (>= 0.9.0)
1825
redis-client (0.10.0)
1926
connection_pool
2027
sqlite3 (1.5.2-x86_64-linux)
28+
webrick (1.7.0)
2129
zeitwerk (2.6.1)
2230

2331
PLATFORMS
2432
x86_64-linux
2533

2634
DEPENDENCIES
2735
lizarb!
36+
puma (~> 5.6)
37+
rack (~> 3.0)
38+
rackup (~> 0.2.2)
2839
rake (~> 13.0)
2940
redis (~> 5.0)
3041
sqlite3 (~> 1.5)

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,34 @@ SqliteDb.current.call "SELECT name, sql FROM sqlite_master WHERE type = 'table';
5454

5555
```
5656

57+
## Web Server
58+
59+
Try Liza with the Rack Web Server
60+
61+
$ liza web
62+
63+
http://localhost:3000/
64+
65+
http://localhost:3000/xxxxxxx
66+
67+
http://localhost:3000/api/xxxxxxx
68+
69+
http://localhost:3000/api/auth/sign_up
70+
71+
http://localhost:3000/api/auth/sign_in
72+
73+
http://localhost:3000/api/auth/account
74+
75+
http://localhost:3000/api/auth/sign_out
76+
77+
http://localhost:3000/assets/app.css
78+
79+
http://localhost:3000/assets/app.js
80+
81+
## Usage
82+
83+
TODO: Write usage instructions here
84+
5785
## Development
5886

5987
To install dependencies, run this bash script:

app.code.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
# happy variables
88

99
# net variables
10+
11+
# web variables

app.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
# happy variables
88

99
# net variables
10+
11+
# web variables

app.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
system :dev
77
system :happy
88
system :net
9+
system :web
910

1011
# Modes help you organize your application's behavior and settings.
1112
# Learn more: http://guides.lizarb.org/modes.html

app/web/requests/api_request.rb

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
class ApiRequest < AppRequest
2+
3+
def self.call env
4+
path = env["REQUEST_PATH"]
5+
6+
#
7+
8+
status = 200
9+
headers = {
10+
"Framework" => "Liza #{Lizarb::VERSION}"
11+
}
12+
body = ""
13+
14+
#
15+
16+
segments = Array path.split("/")[1..-1]
17+
18+
case segments
19+
in "api", "auth", "sign_up"
20+
body = render_route_api_auth_sign_up
21+
in "api", "auth", "sign_in"
22+
body = render_route_api_auth_sign_in
23+
in "api", "auth", "account"
24+
body = render_route_api_auth_account
25+
in "api", "auth", "sign_out"
26+
body = render_route_api_auth_sign_out
27+
in "api", "users"
28+
body = render_route_api_users
29+
else
30+
status = 404
31+
body = render_route_not_found env["LIZA_PATH"]
32+
end
33+
34+
log status
35+
[status, headers, [body]]
36+
end
37+
38+
def self.render_route_api_auth_sign_up
39+
"route: render_route_api_auth_sign_up"
40+
end
41+
42+
def self.render_route_api_auth_sign_in
43+
"route: render_route_api_auth_sign_in"
44+
end
45+
46+
def self.render_route_api_auth_account
47+
"route: render_route_api_auth_account"
48+
end
49+
50+
def self.render_route_api_auth_sign_out
51+
"route: render_route_api_auth_sign_out"
52+
end
53+
54+
def self.render_route_api_users
55+
"route: render_route_api_users"
56+
end
57+
58+
def self.render_route_not_found path
59+
"route: render_route_not_found #{path}"
60+
end
61+
end

app/web/requests/api_request_test.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class ApiRequestTest < AppRequestTest
2+
3+
test :subject_class do
4+
assert subject_class == ApiRequest
5+
end
6+
7+
test :actions, :root do
8+
env = {
9+
"REQUEST_PATH" => "/",
10+
}
11+
12+
status, headers, body = subject_class.call env
13+
14+
assert status == 404
15+
assert headers["Framework"].to_s.start_with? "Liza"
16+
assert body.first.include? "render_route_not_found"
17+
end
18+
19+
test :actions, :sign_up do
20+
env = {
21+
"REQUEST_PATH" => "/api/auth/sign_up",
22+
}
23+
24+
status, headers, body = subject_class.call env
25+
26+
assert status == 200
27+
assert headers["Framework"].to_s.start_with? "Liza"
28+
assert body.first.include? "render_route_api_auth_sign_up"
29+
end
30+
31+
end

app/web/requests/app_request.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Set up your request controllers per the DSL in http://guides.lizarb.org/controllers/request.html
2+
3+
class AppRequest < Liza::Request
4+
5+
end

0 commit comments

Comments
 (0)