SmartMirror icon indicating copy to clipboard operation
SmartMirror copied to clipboard

[discussion] good way to share files among client and server

Open binora opened this issue 8 years ago • 15 comments
trafficstars

we currently share the config file among client and server by mirroring it. This won't scale when more files need to shared and there would be lots of moving parts. Need to find a clean way to keep things simple.

  1. Maybe we can run eject to get hold of webpack, but i'm not sure of other consequences it might have ( maybe none).

need more opinions.

binora avatar Oct 05 '17 08:10 binora

If we do eject, what would we want to do later? https://moduscreate.com/es6-es2015-import-no-relative-path-webpack/ and https://stackoverflow.com/questions/27502608/resolving-require-paths-with-webpack and https://webpack.js.org/configuration/resolve/#resolve-alias

jakkra avatar Oct 05 '17 10:10 jakkra

well, I also found this :

  1. https://medium.com/@ktruong008/absolute-imports-with-create-react-app-4338fbca7e3d
  2. https://github.com/timoxley/linklocal

I'm yet to test the above . Meanwhile, I'm also testing eject and trying out the links you mentioned.

binora avatar Oct 05 '17 12:10 binora

Awesome! #2 Seems nice and easy, still long path will be necessary thought. It will make some things easier, but all component imports will be very long

jakkra avatar Oct 05 '17 15:10 jakkra

  1. with linklocal , things will get easier but we'll have to add an extra step to start the project.

  2. I also tried creating custom env variables for locales and config paths. But that would mean shifting the dot-dots to .env file from App.js

  3. Other method I thought of is to shift the locales and client.js inside client folder. Sure, it includes changes to server-side code but seems straightforward ( and can keep things simple for future? ).

What do you think ?

binora avatar Oct 06 '17 08:10 binora

Just found this: https://www.npmjs.com/package/clientconfig Looks like exactly what we want?

jakkra avatar Oct 06 '17 09:10 jakkra

Not sure how it can be used with react app . what do you have in mind ? On 06/10/2017 3:05 pm, "Jakob Krantz" [email protected] wrote:

Just found this: https://www.npmjs.com/package/clientconfig Looks like exactly what we want?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jakkra/SmartMirror/issues/43#issuecomment-334707157, or mute the thread https://github.com/notifications/unsubscribe-auth/AGdNPnR0DpOxlyN7NqtZECUSfiPIzge2ks5spfRQgaJpZM4Put37 .

binora avatar Oct 06 '17 09:10 binora

I didn't think of any problem because of react app. Server side it just sends the config as a cookie, which can be retrieved client side. Maybe I miss something, couldn't it just be required in react as usual?

jakkra avatar Oct 06 '17 10:10 jakkra

I'll give it a test to have config as a cookie, otherwise we'll go with your proposal 2 or 3 :)

jakkra avatar Oct 06 '17 17:10 jakkra

Sorry I got a little busy. Yeah, go for it . would be great if that works :) On 06/10/2017 10:50 pm, "Jakob Krantz" [email protected] wrote:

I'll give it a test to have config as a cookie, otherwise we'll go with your proposal 2 or 3 :)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jakkra/SmartMirror/issues/43#issuecomment-334817357, or mute the thread https://github.com/notifications/unsubscribe-auth/AGdNPi6SomR7NX2y_HoyI1LRrVCu_QYTks5spmFLgaJpZM4Put37 .

binora avatar Oct 06 '17 18:10 binora

Couldn't get clientconfig to work server side, since react-create-app uses webpack proxy. Didn't manage to send the cookie.

jakkra avatar Oct 06 '17 21:10 jakkra

hey, so what's the next step ?

binora avatar Oct 10 '17 13:10 binora

As I undertsand with .env the imports client side will need to be client/src/compoment/Clock.js? And to import the config it would be just config, since it's in the root directory? I don't like that the client/src part is necessary, however I really like the idea of not having relative import paths. So I think the pros are greater than the cons :)

jakkra avatar Oct 10 '17 14:10 jakkra

Hey, I tried .env approach. Here's what i did :

  1. bump react-scripts version from 0.7.0 to 1.0.0 to support setting NODE_PATH
  2. I set NODE_PATH=src/ in .env in the client directory
  3. was able to import components like components/<Component>.js
  4. The problem is this : screen shot 2017-10-14 at 12 56 15 pm

Turns out it CRA guys dont' allow any other files outside of the NODE_PATH ( once you set it) Here's a discussion

Have a look and let me know if I missed something. :)

binora avatar Oct 14 '17 07:10 binora

Okey, thanks for looking into it. Maybe we can just move them into source?

jakkra avatar Oct 14 '17 08:10 jakkra

Or there is probably a correct way to have pictures. Like some kind of asset folder. Could look up how it should be done in create react app. I'm a little busy, but hopefully next week I have time to check it out :)

jakkra avatar Oct 14 '17 08:10 jakkra