distilagency / starward

:boom: ReactJS Wordpress Boilerplate
27 stars 9 forks source link

Remove /wp-content filter from sanitising code #98

Open falconmick opened 6 years ago

falconmick commented 6 years ago

https://github.com/distilagency/starward/blob/master/server/init/api.js

line 19->20:

.replace(wpUrlRegex, '')
.replace(wpContentUrlRegex, `${WP_URL}/wp-content`);

This is a bad because applying a mass string manipulation is just a bad idea, it should be the responsibility of the component or query that works with that data to format data.

Where this is used?: I think on an old project I was using links that WP generated for pages, by doing this above replace it would make the URL correct for starward navigation as WP slugs match up with Starward! the line 20 was used to add the WP url back on after we blew it away.

Why remove it? I was adding JSON schema to my project via a settings field. I was so confused why my JSON schema was changing when it shouldn't!! Turns out it was due to this. Move the responsibility of URL fixing to the component using them or on the queries that understand that the data they're receiving are WP slugs that need translating to Starward.