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

Cannot read property 'split' of undefined #18

Open
mheubaum opened this issue Mar 15, 2019 · 9 comments
Open

Cannot read property 'split' of undefined #18

mheubaum opened this issue Mar 15, 2019 · 9 comments

Comments

@mheubaum
Copy link

Hello,

I don't know anything about JS and I get this error. I think it is not finding my .env, right?

C:\Users\Administrator\Dashboard>npm start

> [email protected] start C:\Users\Administrator\Dashboard
> concurrently --kill-others-on-fail "react-scripts start" "npm run server"

[1]
[1] > [email protected] server C:\Users\Administrator\Dashboard
[1] > node ./src/services/server.js
[1]
[1] C:\Users\Administrator\Dashboard\src\services\server.js:15
[1] const allowedHosts = process.env.ALLOWED_HOSTS.split(' ')
[1]                                                ^
[1]
[1] TypeError: Cannot read property 'split' of undefined
[1]     at Object.<anonymous> (C:\Users\Administrator\Dashboard\src\services\ser
ver.js:15:48)
[1]     at Module._compile (internal/modules/cjs/loader.js:701:30)
...
```
@converge
Copy link
Owner

Hey, sounds like it, do you have a .env file in the root folder of the project?

@mheubaum
Copy link
Author

With Project you mean the dashboard, right? I have a file "test.env" in "C:\Users\Administrator\Dashboard" where the dashboard files are.

@converge
Copy link
Owner

the .env file requires to be a hidden file, take a look https://www.computerhope.com/issues/ch000009.htm

@mheubaum
Copy link
Author

It didn't work. Same error. Do I have to change anything in server.js or any other file? I didn't find a config.js

@mheubaum
Copy link
Author

mheubaum commented Mar 20, 2019

I solved my problem with
require('dotenv').config({path:'C:\\Users\\Administrator\\Dashboard\\.env.test'}) in server.js.

But now I have the same issue like others that the Dashboard is only loading. I use INSTAPY_FOLDER=\Users\Administrator\InstaPy in the .env. I can find my logs and db there.

In cmd it says :

[0] Note that the development build is not optimized.
[0] To create a production build, use npm run build.

Any idea?

@converge
Copy link
Owner

Sorry mate, I can solve any issue using *nix / MacOS, but I'm the worst using Windows.

@mateuspestana
Copy link

mateuspestana commented Apr 20, 2019

I'm getting the exactly same error, but I'm on fedora 29. Just figured out what is happening:
The error was because I didn't set ALLOWED_HOSTS on .env file, coz I run instapy on DigitalOcean, so, no localhost:3000. How can I set up the .env in a way that only my IP (not DO's) can access it?

@converge
Copy link
Owner

hey @mateuspestana , you could do that with a firewall, CORS is just for source/target resource control.

I'm going to add a credentials control this month.

@lplit
Copy link

lplit commented May 2, 2019

Sorry to hijack the conversation but my question is kind of related.
How do I allow any and all access to the dashboard?
I run it locally on my rpi, I don't care much about ALLOWED_HOSTS or access control, I want it available to all the devices on the local network.

I tried simply taking out the if test in server.js (L13-15), but that doesn't seem to do the trick.

EDIT:
Got it to work following #9, that is by setting the REACT_APP_API_ENTRY_POINT in the .env file to http://<server_IP>:3000 rather than having localhost.
Can access them now from any device on the local network.

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

4 participants