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

Request to update "default_root" #26

Closed
KangGeunSu opened this issue Aug 25, 2021 · 12 comments
Closed

Request to update "default_root" #26

KangGeunSu opened this issue Aug 25, 2021 · 12 comments

Comments

@KangGeunSu
Copy link

I made an example using totaljs(git)/example/authorization.
example.zip

Common fixes

./views/homepage.html

  • <script src="https://cdn.componentator.com/spa.min@17.js"></script>
    -> <script src="/js/spa.min@17.js"></script>

  • <link rel="stylesheet" href="//cdn.componentator.com/spa.min@17.css" />
    -> <link rel="stylesheet" href="/css/spa.min@17.css" />

  • add
    -> <script src="/js/ui.js"></script>
    -> <link rel="stylesheet" href="/css/ui.css" />

File add

./public/js/
-> spa.min@17.js
-> ui.js

./public/css/
-> spa.min@17.css
-> ui.css

Compare two files

example.zip/authorization

-> total4 original

example.zip/authorization_rw

-> node_modules/total4/utils.js

  • const REG_URLEXT = /(https|http|wss|ws|file):\/\/|\/\/[a-z0-9]|[a-z]:|@\{|/i; (Line 96)
    -> const REG_URLEXT = /(https|http|wss|ws|file):\/\/|\/\/[a-z0-9]|[a-z]:/i;

  • return REG_URLEXT.test(text) ? text : ((text[0] === 'h' ? 'href' : 'src') + '="' + CONF.default_root + (text[pos] === '/' ? text.substring(pos + 1) : text)); (Line 2551)
    -> return REG_URLEXT.test(text) ? text : ((text[0] === 'h' ? 'href' : 'src') + '="' + CONF.default_root + (text[pos] === '/' ? text.substring(pos + 1) : text.substring(pos)));

config

name					: Total.js Auth example

default_root				: /total

// IMPORTANT SETTINGS:
cookie		(generate)	: 10
cookie_secret	(generate)  	: 10

Issues

example.zip/authorization

image

-> Call http://localhost:8000/css/spa.min@17.css
-> No "default_root" when calling "js" or "css".

example.zip/authorization_rw

image

-> Call http://localhost:8000/total/css/spa.min@17.css
-> There is a "default_root" when calling "js" or "css".

Please help me to use "default_root"
Thank you

@petersirka
Copy link
Collaborator

Thank you so much.
Please try it now: $ npm install total4@beta. I have improved the functionality.

@KangGeunSu
Copy link
Author

Tested after confirmation.

Hmm....

example.zip/authorization_rw

-> node_modules/total4/utils.js
return REG_URLEXT.test(text) ? text : ((text[0] === 'h' ? 'href' : 'src') + '="' + CONF.default_root + (text[pos] === '/' ? text.substring(pos + 1) : text)); (Line 2551)

Can't I just change this part?

return REG_URLEXT.test(text) ? text : ((text[0] === 'h' ? 'href' : 'src') + '="' + CONF.default_root + (text[pos] === '/' ? text.substring(pos + 1) : text));

Because 'text' is appended with 'href or src' at the end.

Sorry for my lack of explanation.

@petersirka
Copy link
Collaborator

I have changed the functionality to this:

function $urlremap(text) {
	var pos = text[0] === 'h' ? 6 : 5;
	var url = text.substring(pos, text.length - 1);
	return REG_URLEXT.test(url) ? text : ((text[0] === 'h' ? 'href' : 'src') + '="' + CONF.default_root + (text[pos] === '/' ? text.substring(pos + 1) : text));
}

The current functionality is good. text contains the entire value from the src or href attribute with the attribute name. So first, the method parsers url if it's able to be modified. If yes, then then it changes if by adding a root value from the config. If no, then returns unchanged text.

@KangGeunSu
Copy link
Author

If no, returning unaltered text results in 2 "href or src" due to preceding "((text[0] === 'h' ? 'href' : 'src') + '=".

@petersirka
Copy link
Collaborator

Can you create a small example with that problem? Just download emptyproject and try to simulate the problem. I need to debug it.

@KangGeunSu
Copy link
Author

Can't make it right now...

I can't remember what was inappropriate for const REG_URLEXT = /^(https|http|wss|ws|file):\/\/|\/\/[a-z0-9]|[a-z]:|javascript:|#|@\{|'|"|\(/i;...

const REG_URLEXT = /(https|http|wss|ws|file):\/\/|\/\/[a-z0-9]|[a-z]:/i; is possible, is that ok?

With the example above, we will make the best example.

I like flow!!

@petersirka
Copy link
Collaborator

const REG_URLEXT = /(https|http|wss|ws|file):\/\/|\/\/[a-z0-9]|[a-z]:/i; this is not possible to use because that RegExp rewrites links below:

<a href="javascript:something()">
<a href="#home">
<a href="@{url}">
var str = '<a href="' + str + '">';

and that's not good.

@petersirka
Copy link
Collaborator

If you have any problematic example, then send me it.

@KangGeunSu
Copy link
Author

I checked it over the weekend.

I mostly write FLOW.
I wanted it to be "default_root" in "FLOW"

As a result, now seems to be the case.

It seems appropriate to modify the flow in the current state.

I will try more FLOW and reopen in FLOW.

Thank you very much.

@KangGeunSu
Copy link
Author

KangGeunSu commented Aug 30, 2021

How are you planning to do this?

var str = '<image width="150" height="150" xlink:href="{0}img/theme{1}.png" />'.format(url, common.theme || 'white'));

@petersirka
Copy link
Collaborator

Yes, there was a bug with xlink:href - I forgot on this type of attribute.

@KangGeunSu
Copy link
Author

Has confirmed
image

you are the best!!

The background didn't work either, so I tried to edit it a bit, but you solved it all at once.

It's really great!

Thank you always

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

2 participants