Last active
February 27, 2023 19:41
-
-
Save 0atman/827c7e23f83cb5b56528faf52192037f to your computer and use it in GitHub Desktop.
Full-stack, pure Nim. Backend and JS using the same staticly-typed model.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import htmlgen | |
import jester | |
import data | |
routes: | |
get "/": | |
resp( | |
html( | |
head( | |
script(src="/js/js.js")), | |
body( | |
ul( | |
li(db)))) | |
get "/js/js.js": | |
const result = staticExec "nim -d:release js jsclient.nim" | |
const clientJS = staticRead "nimcache/jsclient.js" | |
resp clientJS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const db* = "database" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import data | |
when isMainModule: | |
echo db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app: | |
nim c app.nim | |
clean: | |
rm app | |
run: | |
./app |
To run this example, nimble install jester
before you make app run
.
I used this layout:
$ tree
.
├── app
├── app.nim
├── data.nim
├── js.nim
├── Makefile
└── public
└── js
└── js.js
Updated to statically build the js code into the app using compiletime magic. (ie, staticExec
and staticRead
)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Both the string on the page and in the console log come from the same source -
db.nim
.