Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Sab669
Sep 24, 2009

Chenghiz posted:

If it's important that the user's input is valid, you should be checking server-side, regardless of whether there is a problem in the client-side validation. Never trust the client for validation.

When the user inputs a value, is it posted to the server automatically, or do they have to submit a form?

I fully agree with you on the first paragraph, but unfortunately I'm not in the position to say "Hey guys our software is dumb as gently caress and we need to change all this" :(

Fortunately it's corporate software so we have some control over our users PCs (ie mandating JS) but yea I know it's not ideal.


They do have to manually post it to the server.

Adbot
ADBOT LOVES YOU

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.
I've got a dumb question that I really cannot figure out.

There is a package that we are relying on NPM/github. However we have to make proprietary changes to the repo. So naturally I have forked the repo. And no these are not changes that can then be resubmitted to the package as an open source contribution.

However for obvious reasons the new fork cannot then be hosted through npm. So I am pretty dumb when it comes to dependencies and what not. In a sense our project is still a little blackbox in its setup to me (I was not original developer) but we use yarn and npm to build our packages/dependencies.

So basically my question is, how the heck do I use this fork in my project? How do I rely on it similar to how I use node_modules and what not. It is a private forked repo, and it cannot be hosted on npm so I feel stupid but how do I reference this new forked package?

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

You can specify a dependency in package.json as a git repo rather than as an npm package.

Doom Mathematic
Sep 2, 2008

Knifegrab posted:

I've got a dumb question that I really cannot figure out.

There is a package that we are relying on NPM/github. However we have to make proprietary changes to the repo. So naturally I have forked the repo. And no these are not changes that can then be resubmitted to the package as an open source contribution.

However for obvious reasons the new fork cannot then be hosted through npm. So I am pretty dumb when it comes to dependencies and what not. In a sense our project is still a little blackbox in its setup to me (I was not original developer) but we use yarn and npm to build our packages/dependencies.

So basically my question is, how the heck do I use this fork in my project? How do I rely on it similar to how I use node_modules and what not. It is a private forked repo, and it cannot be hosted on npm so I feel stupid but how do I reference this new forked package?

If the package you've forked is relatively stable and you aren't wanting to constantly pull updates from that package into your fork, you might consider just calling your package a different name.

E: And host it internally, if that wasn't clear.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Thermopyle posted:

You can specify a dependency in package.json as a git repo rather than as an npm package.

and also as a local directory.

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.
I feel really dumb but I am still confused, can anyone point me to a specific example or something? The repo is private but the repo itself has dependencies that must be npm installed as well.

redleader
Aug 18, 2005

Engage according to operational parameters

Sab669 posted:

I fully agree with you on the first paragraph, but unfortunately I'm not in the position to say "Hey guys our software is dumb as gently caress and we need to change all this" :(

Fortunately it's corporate software so we have some control over our users PCs (ie mandating JS) but yea I know it's not ideal.


They do have to manually post it to the server.

Disable form post on page load until it's valid?

spiritual bypass
Feb 19, 2008

Grimey Drawer

Knifegrab posted:

I feel really dumb but I am still confused, can anyone point me to a specific example or something? The repo is private but the repo itself has dependencies that must be npm installed as well.

There's an example in the docs: https://docs.npmjs.com/files/package.json#repository

Roadie
Jun 30, 2013

Sab669 posted:

I fully agree with you on the first paragraph, but unfortunately I'm not in the position to say "Hey guys our software is dumb as gently caress and we need to change all this" :(

Fortunately it's corporate software so we have some control over our users PCs (ie mandating JS) but yea I know it's not ideal.


They do have to manually post it to the server.

Do the post via xhr instead of a form action, and only after validating all form fields.

necrotic
Aug 2, 2005
I owe my brother big time for this!

Knifegrab posted:

I feel really dumb but I am still confused, can anyone point me to a specific example or something? The repo is private but the repo itself has dependencies that must be npm installed as well.

Put the fork in your main repo under like packages/my-fork and then in your main package.json replace the version for that package with that path. Boom done.

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.

necrotic posted:

Put the fork in your main repo under like packages/my-fork and then in your main package.json replace the version for that package with that path. Boom done.

But now aren't I just storing the entire package in my git repo? As opposed to having that package in its own repo, and pulled when npm or yarn installs?


"The URL should be a publicly available (perhaps read-only) url that can be handed directly to a VCS program without any modification."

Wouldn't this not work since the repo I am forking is going to be private?

Harriet Carker
Jun 2, 2009

Just blew (I think) a phone interview. The question was how to know at site B that the user visited site A at some point in the past, assuming A and B are working jointly. I suggested local storage and the interview said it was ok but not great and pressed me for a better solution but I came up empty. Ideas? I’m still stumped!

The Fool
Oct 16, 2003


If local storage or tracking cookies aren't good enough answers, I'd probably suggest a light-weight analytics api that both sites would use.

Roadie
Jun 30, 2013
Hidden iframes using postMessage would be my go-to option there for non-server-dependent functionality that can share cookies and localstorage data across domains.

Edit: Also, I think they mostly work around the nebulous spooky black-box anti-tracking behavior that's in Safari now.

Roadie fucked around with this message at 02:36 on Jun 19, 2018

Chenghiz
Feb 14, 2007

WHITE WHALE
HOLY GRAIL
Put a link to site A on site B and check its style using getComputedStyle to see if it's been visited or not.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Chenghiz posted:

Put a link to site A on site B and check its style using getComputedStyle to see if it's been visited or not.
If you're going to do it by requesting between sites you could use cross-origin resource sharing and make a proper AJAX request of the other site, rather than trying to infer information from styles.
Or go nuts and encode your information into the colors of a png-encoded image, since those are allowed cross-site by default.

Edit: later realized the suggestion I'm replying to was not to load something from the other site but to literally just put a link and interpret whether the browser styles it :visited or not.

roomforthetuna fucked around with this message at 00:56 on Jun 20, 2018

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Chenghiz posted:

Put a link to site A on site B and check its style using getComputedStyle to see if it's been visited or not.

i thought you were joking but somebody actually made a library that does this. https://readwrite.com/2008/05/28/socialhistoryjs_see_which_site/

necrotic
Aug 2, 2005
I owe my brother big time for this!

Knifegrab posted:

But now aren't I just storing the entire package in my git repo? As opposed to having that package in its own repo, and pulled when npm or yarn installs?

And? Isn't the fork for changes specific to your project? If you need it for more than one project then yeah a separate repo, otherwise there's zero reason for the separation.

Harriet Carker
Jun 2, 2009

roomforthetuna posted:

If you're going to do it by requesting between sites you could use cross-origin resource sharing and make a proper AJAX request of the other site

Can you elaborate a little more here? I don’t understand what sort of request to make. Do you mean something like POST the IP address on A and try to GET it on B and see if it exists in a database? Or am I way off track here?

IAmKale
Jun 7, 2007

やらないか

Fun Shoe

roomforthetuna posted:

If you're going to do it by requesting between sites you could use cross-origin resource sharing and make a proper AJAX request of the other site

dantheman650 posted:

Can you elaborate a little more here? I don’t understand what sort of request to make. Do you mean something like POST the IP address on A and try to GET it on B and see if it exists in a database? Or am I way off track here?
roomforthetuna is talking about CORS. It's something configured server-side as a security measure to limit which websites can make requests to that server. For example it can be used to restrict code in a .js file loaded in http://bar.com from making requests to API endpoints at http://foo.com.

However, in the case of cross-site visitation analytics, http://foo.com could be configured on the backend to allow requests from http://foo.com AND http://bar.com at which point visitation analytics could be sent from http://bar.com to mingle with similar data sent from the website served at http://foo.com. Does that make sense?

Harriet Carker
Jun 2, 2009

IAmKale posted:


However, in the case of cross-site visitation analytics, http://foo.com could be configured on the backend to allow requests from http://foo.com AND http://bar.com at which point visitation analytics could be sent from http://bar.com to mingle with similar data sent from the website served at http://foo.com. Does that make sense?

No, and I guess this is why I blew the interview. I don’t know what visitation analytics are or how to store or send them. I also don’t know what you mean by letting the data mingle. Feel free to explain or just let it go - I clearly have a lot to learn.

SimonChris
Apr 24, 2008

The Baron's daughter is missing, and you are the man to find her. No problem. With your inexhaustible arsenal of hard-boiled similes, there is nothing you can't handle.
Grimey Drawer
Are the analytics GDPR compliant? One advantage of the localstorage solution is that the data doesn't have to leave the user's computer.

IAmKale
Jun 7, 2007

やらないか

Fun Shoe

dantheman650 posted:

No, and I guess this is why I blew the interview. I don’t know what visitation analytics are or how to store or send them. I also don’t know what you mean by letting the data mingle. Feel free to explain or just let it go - I clearly have a lot to learn.
Sorry for some of the hand-wave-yness of my post, let me back up a bit. I apologize in advance for the incoming wall of text.

First off, let's just shorten "visitation analytics" to "analytics". At the end of the day website analytics tools like Google Analytics are tasked with submitting requests to a server with information related to an "event" that occurs on a webpage. In the context of the browser, such "events" can include things like, "user clicked something", "user moused over something", or "something on the page scrolled into view". These data points are valuable to organizations as they often want to try and profile the types of users who interact with a site, measure site performance, and determine which parts of the site see the most traffic. This is the high-level goal of analytics.

The "something" in those examples corresponds to whatever types of interactions the site admins are interested in tracking. For example, analytics events may be sent when the "related items" section of an ecommerce site is scrolled into view to indicate that the user moved far enough down the page to view that part of the site. A different event could be sent with an item ID whenever that item is clicked. With enough of these types of data points, site admins can analyze the data to generate conclusions that X section of the site is often seen, or Y item in the showcase is almost never clicked on.

The structure of these analytics requests is implementation-specific. IIRC Google Analytics submits analytics events as GET requests with a bunch of query parameters. Other analytics libraries might accept JSON payloads with necessary properties defined within. At the end of the day, it's simply the frontend submitting requests to the backend with the necessary data. Since this is the JS thread, imagine using the axios library to make a POST request to a URL. The data you'd submit would come from event handlers you'd register in the DOM (as in a <button>'s onclick) or in JS (as with domRef.addEventListener()). That in a nutshell is how you'd collect and submit analytics events from the front end.

On the backend, these events are often stored in some kind of database. That's outside of the scope of this as typically in JS land you'll only need to worry about submitting data to a URL. The server listening at that URL will take care of writing the data to the database.

When I mentioned "let the data mingle", I was trying to convey the idea that analytics events from multiple sites can co-exist in a single database. If CORS is configured such that analytics events submitted from webpages at http://foo.com and http://bar.com can both be submitted to, say, http://api.foo.com then all of those events, even though they represent interactions at two different websites, can still exist within the database. The database doesn't really care where the data comes from, it's all just bits in the end.

Does that help?

IAmKale fucked around with this message at 23:06 on Jun 19, 2018

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop
I dunno about them but it helped me to read that, thanks

Cross-origin policy is also what get cited in Chrome when files in your local filesystem are protected and prevented from being served to pages you also opened locally using the file:/// protocol (from double clicking the html file open). For some people that's the first time the hear about CORS and it confuses them but now looking at Chrome it seems they've changed their message to something else so maybe they don't try to call that CORS related anymore. If so that's good.

Harriet Carker
Jun 2, 2009

Thanks for the explanation. I understand all of that, but I still am not sure what exactly I’m tracking. Did I have it right that I would basically grab and post the IP and time stamp to the analytics database and then attempt a GET on the second site to see if it exists in whatever range I’m concerned with?

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Bruegels Fuckbooks posted:

i thought you were joking but somebody actually made a library that does this. https://readwrite.com/2008/05/28/socialhistoryjs_see_which_site/

It was a huge privacy thing back in the day. Then the browsers went and made it harder to do certain things on visited links to prevent leaking user history.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

IAmKale posted:

roomforthetuna is talking about CORS. It's something configured server-side as a security measure to limit which websites can make requests to that server. For example it can be used to restrict code in a .js file loaded in http://bar.com from making requests to API endpoints at http://foo.com.
This description seems weird to me - the thing is more that javascript is generally restricted by the browser from making cross-site requests for data (except then people worked around this by returning a page of generated javascript that calls a function with the data, and at the client-side modifying the DOM to add new 'script' elements to make the request, so I'm not really sure what purpose the restriction serves other than to make it more of a pain in the rear end. If anything this restriction causes security issues by making people run foreign javascript to call an API instead of being able to just communicate in data).

Anyway, my point here is that the server-side CORS configuration (which is headers you send with the page) is not so much used to restrict a script from making requests of foreign endpoints, but rather is used to tell the browser to not restrict those requests like it normally would.

IAmKale
Jun 7, 2007

やらないか

Fun Shoe

roomforthetuna posted:

Anyway, my point here is that the server-side CORS configuration (which is headers you send with the page) is not so much used to restrict a script from making requests of foreign endpoints, but rather is used to tell the browser to not restrict those requests like it normally would.
Thank you for calling this out, I clearly didn't understand exactly how CORS settings on the backend enable cross-domain requests. So when making API requests from within a SPA, for example, it's the browser that allows cross-domain requests provided the preflight OPTIONS response from the API server includes a Access-Control-Allow-Origin header containing an * or the domain (the Origin header in the OPTIONS request) the SPA is being served from?

MrMoo
Sep 14, 2000

Pretty much, but then it goes into particular fields and whether credentials are permitted and things about when additional preflight requests are required. Usually browsers are nice enough they tell you what is wrong and how to fix it.

Anything with cookies and CORS is going to suck because CORS attacks usually work due to cookies.

Dominoes
Sep 20, 2007

Looking for advice on why I'm getting CORS errors when trying ES6 imports. No webpack; just Typescript-compiled files*, run locally without a server.

Error in Firefox:
code:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///C:/Users/david/code/dimensions/frontend2/build/dist/index.js. (Reason: CORS request not http).
Module source URI is not allowed in this document: “file:///C:/[s]Users[/s]/david/code/dimensions/frontend2/build/dist/index.js”.
Chrome:
code:
Access to Script at 'file:///C:/Users/david/code/dimensions/frontend2/build/dist/index.js' from origin 'null' has been blocked by CORS policy: Invalid response. Origin 'null' is therefore not allowed access.
Offending line that triggers this, in my HTML file. Tried head and body:
code:
<script type="module" src="../build/dist/index.js"></script>
using type="text/javascript" doesn't trigger this error, but also doesn't allow for (native) es6 imports.

*Also tried with an empty index.js for troubleshooting; still throws error.

Related: Have y'all tried native imports? What do you think? I assume they're not suitable for production code due to the prevalence of old browser versions that don't support it.

Dominoes fucked around with this message at 00:57 on Jul 5, 2018

mystes
May 31, 2006

Isn't it simply not permitted to load javascript from file urls nowadays at all, even from within local html files? I think there's a command line flag for chrome if you really need it, but you're basically just expected to run an http server for testing now.

Dominoes
Sep 20, 2007

Thank you. I fired up a simple rust http server, and no longer receive this error; working through the next one now:


(Chrome)
code:
Uncaught TypeError: Failed to resolve module specifier "react". Relative references must start with either "/", "./", or "../".
It's taking my module imports, but not npm ones.

I suspect this could be resolved by importing the modules directly, but this isn't working:
code:
import * as React from '../node_modules/react/cjs/react.development.js'

Dominoes fucked around with this message at 01:28 on Jul 5, 2018

Doom Mathematic
Sep 2, 2008

Dominoes posted:

It's taking my module imports, but not npm ones.

In general, an explicit relative import should only be used to load other source files from elsewhere in your own module. If you're pulling in a dependency, you don't know for sure where that dependency will be installed, so try:

JavaScript code:
import React from 'react'
Also note how we're getting the default (unnamed) import and naming it React, not grabbing a single object containing all the named imports * as React. These are not the same thing.

Roadie
Jun 30, 2013
Use a bundler like Parcel and that will solve most of the weird stuff you're going to repeatedly run into trying to use tsc's results directly. Parcel also has a no-hassle dev server with nice stack traces and stuff built in.

Also, so you never have to worry about the * as thing, set "allowSyntheticDefaultImports": true and "esModuleInterop": true in your tsconfig.json and you should never have to think about it again.

Roadie fucked around with this message at 01:58 on Jul 5, 2018

Dominoes
Sep 20, 2007

Thanks dudes. This appears to be an issue of TSC not knowing how to deal with importing node modules as files, and es6 imports having the opposite problem; diagnosing by editing the compiled files directly to point to .js files. Fighting a mime issue now. (And will have to re-attack how to workaround this).

Roadie: That TSconfig setting sounds lovely! The import * as syntax is awk. I'm hoping to avoid bundlers entirely (not realistic?), but Parcel looks nice from a skim.

Dominoes fucked around with this message at 02:04 on Jul 5, 2018

necrotic
Aug 2, 2005
I owe my brother big time for this!
Avoiding bundlers is going to make things very painful for you. Just use parcel, you'll be much happier in the long run.

huhu
Feb 24, 2006
Has anyone used an A/B testing library with React? Any opinions/preferences/things to avoid?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
parcel? what happened to microbundle fusebox rollup webpack brunch broccoli browserify?

necrotic
Aug 2, 2005
I owe my brother big time for this!
Everything is a fad in the world of web dev. Parcel is the new one?

Adbot
ADBOT LOVES YOU

huhu
Feb 24, 2006
:sigh: I was just getting used to Webpack.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply