Making a werc app

Let's make a hello world app for werc. However unlike the one included with werc, ours will actually work.

First, you need to make a directory in your werc/apps/ with the name of the app. I'm going to call mine hello.

Next make a file called app.rc inside your app's directory. This is the script that's called when enabling and executing your app.

You need a function called conf_enable_hello in your app.rc. The example hello app included with werc left this out for some reason...

fn conf_enable_hello {
    	conf_enable_app hello
}

This enables the app when you set the line conf_enable_hello in your site's _werc/config.

You need to provide a function called hello_init. This is called on each page for your app to be able to handle things.

In the function, you'll want to check to see if you need to run your app or not. For our app, we need to perform a path check to ensure it only runs for our desired path. The requested path is in the variable $req_path so you can check using an if statement. You'll want to set the handler_body_main variable to your body handler function to be able to change the body of the page.

fn hello_init {
	if(~ $req_path /hello) {
		handler_body_main='hello_body'
	}
}

Inside your body handler function you can add whatever code your app is going to run. Send anything to stdout from your function to have the output appear on your page:

fn hello_body {
	echo 'hello werc!'
}

And that's it! You should be able to navigate to your.site/hello to see the output.

Some useful things: