easy to use http server that allows for using javascript just as php was used back in the days
Warning
as the issues indicate, a lot of breaking changes are ahead. make sure to check for these in future until version 1.0.0 is relessed.
go into the directory where you want to have your project and run
$ npx --yes rtjscomp@latest
or in case you prefer bun:
$ bunx --bun rtjscomp@latest
and now http://localhost:8080 offers a greeting!
for developing rtjscomp itself, clone this repository and run
$ npm install
$ npm start
it is only needed if you want to change default settings. it has the following properties:
gzip_level
: compression level, 0-9, default is 9log_verbose
: boolean, set true for more verbose logging or run with -vpath_aliases
: object where the key is the url path and the value is the file pathpath_ghosts
: array of paths that are simply ignored, no response is sentpath_hiddens
: array of paths that give 404path_statics
: array of paths in which nothing is transpiled, but the file is sent as isport_http
: port for http server, default is 8080port_https
: port for https serverservices
: paths to (enabled) service files, prepend an entry with # to disable ittype_dynamics
: dynamic file types, see apitype_mimes
: file type to mime type map (most common are already set, only overrides)type_raws
: array of file types that are sent uncompressed
here is an example for a customized setup:
{
"path_aliases": {
"": "index.html",
"blog": "modules/blog/index.html",
"blog/*id": "modules/blog/article.html"
},
"path_ghosts": [ "admin", "wp-admin" ],
"path_hiddens": [ "secrets.html" ],
"path_statics": [ "rawtruth.html" ],
"port_http": 8080,
"services": [
"modules/blog/blog",
"#modules/not/needed"
],
"type_dynamics": [ "html", "js" ],
"type_mimes": {
"html": "text/html; charset=UTF-8",
"js": "application/javascript; charset=UTF-8",
"custom": "application/custom"
},
"type_raws": [ "png", "jpg", "pdf" ]
}
on first run, they will be created with some defaults.
- data dir, services store their data or read custom config files here
- public dir, containing dynamic and static offerings and also services
- static files like .png in public dir are sent to requests 1:1, maybe compressed
- dynamic files like .html are internally transpiled/compiled and executed -> "rtjscomp"
- .service.js files are executed and their
this
can be accessed by other files, they are not accessible to outside
example:
public
├── index.html
├── modules
│ ├── blog
│ │ ├── article.html
│ │ ├── blog.service.js
│ │ └── index.html
│ └── not
│ └── needed.service.js
├── rawtruth.html
└── secrets.html
in every served dynamic file (like .html), you can insert <?
and ?>
tags to insert javascript code that is executed server-side. <?= ... ?>
can be used to insert the result of an expression.
request-independent services can be created using .service.js files referenced in services.txt.
in both file types (dynamic served and services), you can use all node/bun methods including require
, but also those:
log(msg)
: logs the message to the consoleservice_require(service path)
: returns the matching service objectservice_require_try(service path)
: returns the matching service object or null if not found or if disabledrtjscomp
: has these properties/methods:actions
: an object with methods for server control (http[s]_[start|stop|kill], log_clear, halt, exit)async data_load(path)
: reads the file in data directory and returns its content or nullasync data_load_watch(path, callback(content))
: executes callback first and on every changeasync data_save(path, content)
: writes the content to the file in data directory
- node 8.0.0 or higher
- bun
any os