How to access manifest.json in tiddlywiki

I imitated the following the below code to try to access the http://xxxxx/manifest.json file, but the js file can only work normally as a shadow. After being packaged as a plugin, it will not work.Did I go wrong somewhere?

/*\
title: $:/core/modules/server/routes/get-favicon.js
type: application/javascript
module-type: route

GET /favicon.ico

\*/
(function() {

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

exports.method = "GET";

exports.path = /^\/favicon.ico$/;

exports.handler = function(request,response,state) {
	var buffer = state.wiki.getTiddlerText("$:/favicon.ico","");
	state.sendResponse(200,{"Content-Type": "image/x-icon"},buffer,"base64");
};

}());

Could you please post the actual code that you used?

1 Like
/*\
title: get-manifest.js
type: application/javascript
module-type: route

GET /manifest.json

\*/

(function () {
  /*jslint node: true, browser: true */
  /*global $tw: false */
  "use strict";

  exports.method = "GET";

  exports.path = /^\/manifest.json$/;

  exports.handler = function (request, response, state) {
    const buffer = state.wiki.getTiddlerText("$:/manifest.json");
    state.sendResponse(
      200,
      { "Content-Type": "application/json" },
      buffer
    );
  };
})();

Basically nothing has changed except the file name.

Hi @oeyoews the core loads the route modules by enumerating all the modules of type route. To be loaded as a module the tiddler needs to be loaded by the boot kernel so that the module definition is available during startup when the modules are initialised.

You could add some temporary logging in the server.addRoute() to check whether your module is being loaded.

1 Like

All indicate that it is loaded, but the http://127.0.0.1:8080/manifest.json route can only be accessed in the shadow state. Iā€™m confused

The underlying issue is likely to do with the loading order of the routes, and that another route module that matches the same path is loading first when your module is part of a plugin.

I tried to put the get-manifest.js file in core. The order of loading routes is as follows. At this time, the http://127.0.0.1:8080/manifest.json route can be accessed.

/^\/([^\/]+)$/ It is this routing problem that affects it, test it by comment get-html-tiddler.js file

It will affect all single file routing in the root directory and will not affect folder routing. Since /favicon.ico is in front of it, it is not affected.

get-html-tiddler.js supports the static functions of tiddlywiki, such as http://127.0.0.1:8080/#GettingStarted and http://127.0.0.1:8080/GettingStarted can be accessed at the same time, so it will conflict with custom routing , there seems to be no good solution at present,

Try renaming the tiddler for your module to $:/_get-manifest.js. Remember to also rename the commented metadata at the top of the code.

The current solution I can think of is to add a layer of routing, such as using /public/manifest.json instead of /manifest.json