Skip to content

Commit

Permalink
Move to qub folder, add conf file, rename app to server.bas
Browse files Browse the repository at this point in the history
  • Loading branch information
jamonholmgren committed Nov 29, 2023
1 parent 6556aa8 commit c780ed1
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 36 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ qub create

It'll ask you for your domain name (e.g. jamon.dev) which doubles as your project's folder name. It will also ask if you want to install QB64 (I recommend you do).

When done, you can CD into the new folder and run `./bin/build` to build the website. Then, run `./app` to start the web server. Visit [http://localhost:6464/](http://localhost:6464/) to view the website.
When done, you can CD into the new folder and run `./bin/build` to build the website. Then, run `./server` to start the web server. Visit [http://localhost:6464/](http://localhost:6464/) to view the website.

## Modifying your website

Your new website has the following folder structure:

```
bin
qub
server.bas
qub.conf
web
pages
home.html
Expand All @@ -56,15 +59,12 @@ web
footer.html
header.html
head.html
app.bas
README.md
```

### app.bas

This is the Qub web server. You can modify it if you want to change the port or add more functionality.
### qub/server.bas

However, if you don't modify it, you can periodically update it by running `qub update`. Note this will blow away any modifications you've made, so be careful!
This is the Qub web server. You can periodically update it by running `qub update`. Note this will blow away any modifications you've made, so be careful!

Qub's web server was originally based on [Yacy](https://github.com/smokingwheels/Yacy_front_end) by SmokingWheels, but has been heavily modified since. It comes with a number of features:

Expand All @@ -74,10 +74,10 @@ Qub's web server was originally based on [Yacy](https://github.com/smokingwheels
- [x] Binary file serving (images, fonts, etc)
- [x] Custom 404 page support
- [x] Basic dynamic variable support (e.g. `${year}` in web/footer.html, `${slug}` for use in your navigation, etc)
- [x] Custom port support (via ./qub.conf)
- [ ] Customizable dynamic variable support (coming soon)
- [ ] 301 redirects support (coming soon)
- [ ] Custom 500 page support (coming soon)
- [ ] Custom port support (coming soon)
- [ ] More customizable templating support (coming soon)

It does not (and probably won't) support HTTPS or HTTP2. I recommend putting CloudFlare in front of it in production (more in the [deploy guide](#deploy-guide) below).
Expand Down Expand Up @@ -130,13 +130,13 @@ Once I had a working website, I realized that I wanted to make it easier for oth

Qub is not particularly important to modern technology in the grand scheme of things, but it's been a blast to work on. I hope you enjoy it!

## Future

I'd love to build more QBasic-powered server capabilities. I'm still learning how to utilize QB64 -- for example, in old QBasic, you couldn't include external files, but in QB64 you can.

## TODO

- [ ] Fill out the README, documentation, screenshots
- [ ] Set up CI
- [ ] Add a Deployment doc
- [ ] Make the default template look nicer, better template README
- [ ] htmx version maybe
- [ ] YouTube video on Jamon's Code Quests

## License
Expand Down
20 changes: 11 additions & 9 deletions src/cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ main() {
curl -s $GITHUB_TEMPLATE/README.md > "${DOMAIN}/README.md"
replace_in_file "$DOMAIN/README.md" "DOMAIN" "$DOMAIN"
echo -e "${GREEN}${END} README.md"
curl -s $GITHUB_TEMPLATE/app.bas > "${DOMAIN}/app.bas"
echo -e "${GREEN}${END} app.bas"
curl -s $GITHUB_TEMPLATE/qub/server.bas > "${DOMAIN}/qub/server.bas"
echo -e "${GREEN}${END} qub/server.bas"
curl -s $GITHUB_TEMPLATE/qub/qub.conf > "${DOMAIN}/qub/qub.conf"
echo -e "${GREEN}${END} qub/qub.conf"
curl -s $GITHUB_TEMPLATE/.gitignore > "${DOMAIN}/.gitignore"
echo -e "${GREEN}${END} .gitignore"
curl -s $GITHUB_TEMPLATE/bin/install_qb64 > "${DOMAIN}/bin/install_qb64"
Expand Down Expand Up @@ -149,7 +151,7 @@ main() {
echo -e " ./bin/install_qb64"
fi
echo -e " ./bin/build"
echo -e " ./app"
echo -e " ./server"
echo ""
echo -e "${YELLOW}Support Qub development:${END}"
echo ""
Expand All @@ -167,11 +169,11 @@ main() {
echo "Updating Qub-powered QB64 website project..."
echo ""

# If we don't have an app.bas file, exit
# If we don't have a server.bas file, exit

if [[ ! -f app.bas ]]; then
if [[ ! -f qub/server.bas ]]; then
echo ""
echo -e "${RED}app.bas file not found.${END} Are you in the right folder?"
echo -e "${RED}qub/server.bas file not found.${END} Are you in the right folder?"
echo ""
return 1
fi
Expand All @@ -194,10 +196,10 @@ main() {
return 1
fi

# Download the latest app.bas from the template
# Download the latest server.bas from the template

curl -s $GITHUB_TEMPLATE/app.bas > app.bas
echo -e "${GREEN}${END} app.bas updated to latest"
curl -s $GITHUB_TEMPLATE/qub/server.bas > qub/server.bas
echo -e "${GREEN}${END} qub/server.bas updated to latest"
echo ""

return 0
Expand Down
8 changes: 5 additions & 3 deletions template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ This is a website powered by [QB64](https://www.qb64.org/) and [Qub](https://qub

## Running Locally

Run `./bin/install_qb64` to install dependencies.
Run `./bin/install_qb64` to install the QB64 dependency into `./qb64`.

Run `./bin/build` to build the website locally.
Run `./bin/build` to build the Qub web server.

Run `./app` once you've built to start the webserver on port 6464.
Run `./server` once you've built to start the webserver on port 6464.

Visit [http://localhost:6464/](http://localhost:6464/) to view the website.

Modify `./qub/qub.conf` to change the port and other settings.

## Acknowledgements

- Original QB64 webserver found here: https://github.com/smokingwheels/Yacy_front_end/blob/master/yacyfrontend.bas
2 changes: 1 addition & 1 deletion template/bin/build
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

./qb64/qb64 -x -o ../app ./app.bas
./qb64/qb64 -x -o ../server ./qub/server.bas
6 changes: 3 additions & 3 deletions template/bin/install_qb64
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ echo "This installs QB64 on a computer or server."

ROOT_FOLDER=$(pwd)

# Check if $ROOT_FOLDER/app.bas exists (if not, exit with an error)
if [ ! -f "${ROOT_FOLDER}/app.bas" ]; then
echo "Error: app.bas not found in ${ROOT_FOLDER}"
# Check if $ROOT_FOLDER/qub/server.bas exists (if not, exit with an error)
if [ ! -f "${ROOT_FOLDER}/qub/server.bas" ]; then
echo "Error: qub/server.bas not found in ${ROOT_FOLDER}"
echo "(are you running this from the right folder?)"
exit 1
fi
Expand Down
5 changes: 5 additions & 0 deletions template/qub/qub.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Configuration file for Qub
# Uncomment key=value lines to override the defaults

# The port to use for the Qub server
# port=6462
37 changes: 28 additions & 9 deletions template/app.bas → template/qub/server.bas
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,31 @@ Dim client_host(1 To MAX_CLIENTS) As String
Dim client_browser(1 To MAX_CLIENTS) As String

connections = 0
port$ = DEFAULT_PORT

Print "Starting QB64 webserver on port " + DEFAULT_PORT
' check if qub.conf exists, and read in the configuration if so
If _FILEEXISTS("./qub/qub.conf") Then
Print "Reading configuration from qub.conf"
Open "./qub/qub.conf" For Input As #1
Do While Not EOF(1)
Line Input #1, line$
' Strip any preceding whitespace from line$
Do While Left$(line$, 1) = " "
line$ = Mid$(line$, 2)
Loop

' Read in the config options
If Left$(line$, 5) = "port=" Then
port$ = Mid$(line$, 6)
End If
Loop
Close #1
End If

Print "Starting QB64 webserver on port " + port$

' kick off the listener
host = _OpenHost("TCP/IP:" + DEFAULT_PORT)
host = _OpenHost("TCP/IP:" + port$)

' main loop!
Do
Expand Down Expand Up @@ -112,7 +132,6 @@ Loop Until InKey$ = Chr$(27) ' escape quits
Close #host
System ' Quits to system


StaticFileError:
Print "File error: " + Error$
Resume Next
Expand Down Expand Up @@ -311,7 +330,7 @@ Function handle_request% (c As Integer)
If Len(client_host(c)) = 0 Then client_host(c) = DEFAULT_HOST
End If

'assume the request can be completed; set to 0 if it can't.
' assume the request can be completed; set to 0 if it can't.
handle_request = 1
code$ = "200 OK"
content_type$ = "text/html"
Expand Down Expand Up @@ -435,16 +454,16 @@ Function handle_request% (c As Integer)

Exit Function

not_found:
not_found:
respond c, "HTTP/1.1 404 Not Found", "404 Not Found", "text/html"
Exit Function

large_request:
large_request:
respond c, "HTTP/1.1 413 Request Entity Too Large", "", "text/html"
handle_request = 1
Exit Function

bad_request:
bad_request:
respond c, "HTTP/1.1 400 Bad Request", "", "text/html"
handle_request = 1
Exit Function
Expand All @@ -453,11 +472,11 @@ Function handle_request% (c As Integer)
handle_request = 1
Exit Function

runtime_internal_error:
runtime_internal_error:
Print "RUNTIME ERROR: Error code"; Err; ", Line"; _ErrorLine
Resume internal_error

internal_error:
internal_error:
respond c, "HTTP/1.1 500 Internal Server Error", "", "text/html"
handle_request = 1
Exit Function
Expand Down

0 comments on commit c780ed1

Please sign in to comment.