sjs-4

Server-side JavaScript engine v4. Run JavaScript on the server in an ECMAScript 5.1 compliant VM.

Important notes

  • Execution time is limited in 1sec.
  • Error message formats are not defined, may change in the future.
  • 'use strict' is supported and enabled by default. You can turn it off by setting the file attribute { "useStrict int32": 0 }.
  • Math.random() is seeded form the //request/info file’s random string attribute, which contains a base64 string, currently 16 bytes long, storing a 64bit number. Its length may change in the future. You may want to override it when testing.
  • new Date() returns the current time with second granularity; the same value as returned by request.createdBy().
  • require() asserts that the target file uses the same file type sjs-4.
  • To set Content-Security-Policy headers on the response, set the response file’s content-security-policy string attribute. For example: response.attrStr('content-security-policy', '...').
  • Inline SourceMaps are suppored. Set the sourcemap on the last line, like this:
    response.body('hello world);
    
    //# sourceMappingURL=data:application/json,SnVzdCBhIGR1bW15IGJhc2U2NCBleGFtcGxl

Hello world (content)

To write a hello world content app, create the following file structure:

/hello-world             [type: "app-1"]
/hello-world/.Inline     [type: "sjs-4"]

And put the following content in the .Inline file:

response.body('hello world');

If it doesn’t show up on the page, you likely put the /hello-world file in the wrong bucket.

(A content app is an app embedded in a page, not a full page.)

Hello world (page)

To write a hello world full page app, create the following file structure:

/hello-world             [type: "app-1"]
/hello-world/.Request    [type: "sjs-4"]
/hello-world/.Page

And put the following content in the .Request file:

response.body('hello world');

The .Page file is only needed to make it show up as menu entries.

About the VM

The sjs-4 engine runs on the Goja VM.

Implemented OS Interfaces

.Inline
.Main
.Request