Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] module-type: route not working #4807

Closed
linonetwo opened this issue Aug 12, 2020 · 1 comment
Closed

[BUG] module-type: route not working #4807

linonetwo opened this issue Aug 12, 2020 · 1 comment

Comments

@linonetwo
Copy link
Contributor

Describe the bug

I've created a custom route: get-can-sync.js

/*\
title: $:/plugins/linonetwo/watch-fs/get-can-sync.js
type: application/javascript
module-type: route
GET /watch-fs-can-sync
\*/
(function () {
  exports.method = 'GET';

  exports.path = /^\/watch-fs-can-sync$/;

  console.log('111');
  exports.handler = function (request, response, state) {
    console.log('222');
  };
})();

With get-can-sync.js.meta

creator: LinOnetwo
title: $:/plugins/linonetwo/watch-fs/get-can-sync.js
type: application/javascript
module-type: route

But 111 is logged, 222 is never logged.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new plugin
  2. Place get-can-sync.js and get-can-sync.js.meta
  3. Start the wiki
  4. Goto http://localhost:xxxx/watch-fs-can-sync
  5. 111 logged, no 222

Expected behavior

I can write my custom route in my plugin.

Desktop (please complete the following information):

  • OS: MacOS
  • Browser Firefox
  • Version "tiddlywiki": "5.1.22"

Additional context

I've created a watch-fs plugin #3060 (comment)

I'm going to create an HTTP API that can poll to get status of watch-fs plugin, if it returns true, then in the browser, we invoke a sync from the server to the browser. Otherwise we wait a while.

@linonetwo
Copy link
Contributor Author

I figure out, it is

  {
    method: 'GET',
    path: /^\/([^\/]+)$/,
    handler: [Function (anonymous)]
  },

in the

this.routes [
  {
    method: 'DELETE',
    path: /^\/bags\/default\/tiddlers\/(.+)$/,
    handler: [Function (anonymous)]
  },
  {
    method: 'GET',
    path: /^\/favicon.ico$/,
    handler: [Function (anonymous)]
  },
  {
    method: 'GET',
    path: /^\/files\/(.+)$/,
    handler: [Function (anonymous)]
  },
  { method: 'GET', path: /^\/$/, handler: [Function (anonymous)] },
  {
    method: 'GET',
    path: /^\/login-basic$/,
    handler: [Function (anonymous)]
  },
  {
    method: 'GET',
    path: /^\/statuss$/,
    handler: [Function (anonymous)]
  },
  {
    method: 'GET',
    path: /^\/([^\/]+)$/,
    handler: [Function (anonymous)]
  },
  {
    method: 'GET',
    path: /^\/recipes\/default\/tiddlers\/(.+)$/,
    handler: [Function (anonymous)]
  },
  {
    method: 'GET',
    path: /^\/recipes\/default\/tiddlers.json$/,
    handler: [Function (anonymous)]
  },
  {
    method: 'PUT',
    path: /^\/recipes\/default\/tiddlers\/(.+)$/,
    handler: [Function (anonymous)]
  },
  {
    method: 'GET',
    path: /^\/status$/,
    handler: [Function (anonymous)]
  },
  {
    method: 'GET',
    aaa: 'bbb',
    path: /^\/watch-fs-can-sync$/,
    handler: [Function: handler]
  }
]

that short circuit the incoming request, it will match all the request url that is without "/", so if user defined route is without "/", then it will be ignored.

So the solution is simple:

Use /linonetwo/watch-fs-can-sync instead of /watch-fs-can-sync

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant