Skip to content

Commit

Permalink
FEAT: Root-less configuration possibility (default)
Browse files Browse the repository at this point in the history
resolves: #2
  • Loading branch information
Oldes committed May 9, 2023
1 parent 4a1f774 commit f70d8ee
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,17 @@ Based on '[A Tiny HTTP Server](https://github.com/earl/rebol3/blob/master/script

## Usage:

Check [%server-test.r3](https://github.com/Oldes/Rebol-HTTPd/blob/master/server-test.r3) script how to start a simple server}
Minimal server setup:
```rebol
http-server/actor 8888 [
;- Server's actor functions
On-Header: func [ctx][
;; Just respond with data we recieved...
ctx/out/status: 200
ctx/out/header/Content-Type: "text/plain; charset=UTF-8"
ctx/out/content: mold ctx/inp
]
]
```

For more complete server setup check [%server-test.r3](https://github.com/Oldes/Rebol-HTTPd/blob/master/server-test.r3) script.
24 changes: 13 additions & 11 deletions httpd.reb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Rebol [
Title: "HTTPD Scheme"
Type: module
Name: httpd
Date: 09-Jan-2023
Version: 0.7.0
Date: 09-May-2023
Version: 0.8.0
Author: ["Andreas Bolka" "Christopher Ross-Gill" "Oldes"]
Exports: [http-server decode-target to-CLF-idate]
Home: https://github.com/Oldes/Rebol-HTTPd
Expand Down Expand Up @@ -34,6 +34,7 @@ Rebol [
02-Jul-2020 "Oldes" {Added possibility to stop the server from a client and return data to it (useful for OAuth2)}
06-Dec-2022 "Oldes" {Added minimal support for WebSocket connections}
09-Jan-2023 "Oldes" {New home: https://github.com/Oldes/Rebol-HTTPd}
09-May-2023 "Oldes" {Root-less configuration possibility (default)}
]
Needs: [3.10.1 mime-types]
]
Expand Down Expand Up @@ -215,7 +216,7 @@ sys/make-scheme [
]
subport/extra/config:
config: make object! [
root: system/options/home
root: none
index: [%index.html %index.htm]
keep-alive: true
server-name: "Rebol3-HTTPd"
Expand All @@ -239,7 +240,7 @@ sys/make-scheme [
/local target path info index modified If-Modified-Since
][
target: ctx/inp/target
target/file: path: join dirize ctx/config/root next clean-path/only target/file
target/file: path: join ctx/config/root next clean-path/only target/file
ctx/out/header/Date: to-idate/gmt now
ctx/out/status: 200
either exists? path [
Expand Down Expand Up @@ -931,16 +932,17 @@ http-server: function [
server: open join httpd://: port
if config [
if object? spec [ spec: body-of spec ]
case [
file? spec/root [spec/root: dirize clean-path spec/root]
none? spec/root [spec/root: what-dir]
spec/root: case [
file? spec/root [to-real-file dirize clean-path spec/root]
spec/root = 'current-dir [what-dir]
'else [none]
]
append server/extra/config spec
]
unless system/options/quiet [
? server/extra/config
]

sys/log/info 'HTTPD ["Root directory: " as-green server/extra/config/root]

;unless system/options/quiet [? server/extra/config]

if actor [
append server/actor either block? actions [
Expand Down

0 comments on commit f70d8ee

Please sign in to comment.