Class: GeneralStatic

base.GeneralStatic()

This class provide a basic interface for carrying out actions required for providing static content. Here Static Content is taken to mean content that is created previous to the launch of the application.

The application sets a static store by passing a class (constructor) to the GeneralStatic constructor as in new GeneralStatic(MyStaticStoreClass) v.s. new GeneralStatic(), which uses the general database static storage class.

This static storage is not a replacement for all ways of serving static files. The primary web server of an website might be the best place for setting up static file service.

The presence of this class in the library can be used in conjunction with the contractual access clases. And, there may be some files best stored with the application code - and that might have more to do with installation of an application than configuring the static load.

Also, this module has methods for preparing JSON descriptors of HTML and JavaScript that goes with it. This allows for parts of pages to be delivered as lazy loaded components.

Finally, some processes may request files from the local process.

Constructor

new GeneralStatic()

Source:

Methods

(async) fetch(asset_key, etc) → {object}

This method may be the point of this module. It attempts to find a static asset and return an object describing it if it does find it.

The contractual methods that use this method prefer to have an object delivered wiht two fields mime_type and string. The first field identifies the type of object that it is, the second is the string representation of the object.

In most cases, this returns an object from the _preloaded table. But, if the object is not there, this method will try to find it in the DB or in the custom static store.

Parameters:
Name Type Description
asset_key string
etc object

and object to pass to static_store if used.

Source:
Returns:
Type
object

generic_prep_cwd_offset(conf)

Some applications call this method during preloading. This method looks for the field app_spec on the static_files field of the configuration object.

After making an attemp to clean up the string, which is a relative directory to the root directory, this method update all the fname fields of the descriptors stored in the _preloaded map.

Parameters:
Name Type Description
conf object
Source:

initialize(db_obj, conf)

Loads files from locations that are identified in the static_files field of the configuration. The static_files object may have a directory field, in which case all the files in the directory will be loaded. Otherwise, it will have a map of files, files, which will be transfered into the _preloaded map.

Once all the entries are established in the map _preloaded, they data is loaded into the map for later access.

Parameters:
Name Type Description
db_obj object
conf object
Source:

preload_all(conf)

The configuration object is available for those applications that use it to identify files to be loaded.

The result of calling this method should be that the table _preloaded[fileKey] should have a number of assests stored in memory for later retrieval.

If the custom_static_store has been set up using a parameter to the constructor (AppStaticStorageClass), the custom store will be used to load the _preloaded map. Otherwise, files will be loaded from the paths found in thie objects stored in the the _preloaded map.

Parameters:
Name Type Description
conf object
Source:

prepare_asset(data) → {object}

Some assets are delivered to the web app as an object with two parts, script and html... This takes an html page (maybe just some part of one) with script and html. It splits the page into the two parts and then it stores the pair for delivery.

Parameters:
Name Type Description
data Buffer
Source:
Returns:
  • this is an object with two fields, html and script.
Type
object

(async) reload(fileKey) → {string}

Parameters:
Name Type Description
fileKey string
Source:
Returns:
Type
string

set_transition_engine(transition_engine)

Set the transion engine reference.

Parameters:
Name Type Description
transition_engine object

a reference to the application transition engine

Source:

static_store(asset_key, etc) → {object|boolean}

static_store -- a custom store supplied by the application in lieu of other other stores the application may supply to the db the app might not want to call out a DB implementation... so this is a little extra This makes the supplied static store custom for just the static pathways and falls out of scope of other assets managed through the DB. (Use this option carefully)

Parameters:
Name Type Description
asset_key *
etc *
Source:
Returns:

returns false if no custom_static_store has been set up. Returns the result of custom_static_store.fetch othewise.

Type
object | boolean