darul75 / web-react

:diamond_shape_with_a_dot_inside: Another React Dev Kit with Webpack and NodeJS
https://react-web.herokuapp.com/
81 stars 8 forks source link

npm run dev prevent api calls #20

Open allannaranjo opened 8 years ago

allannaranjo commented 8 years ago

I used web-react as a boilerplate, when I build the app (npm run build) and then npm run start the app launches in the port 3000, in the root (http://localhost:3000/) I see the app being rendered and in the same port I can make calls to an api end point I created (GET http://localhost:3000/api/me). However when I do npm run dev, the app loads in the port 8080 and it renders the front end in the root but if I do http://localhost:8080/api/me I get PAGE NOT FOUND. Why is this happening?

Regards

darul75 commented 8 years ago

Hi, With dev mode there is no nodejs server behind, just a webpack "server" handler. In Readme, look for next section called DEV ONLY CLIENT/SERVER

allannaranjo commented 8 years ago

I did that and it is supposed to start the app in http://localhost:8081 however all I get in the browser is: Cannot GET / for both front end and api calls.

Regards,

On Wed, Jan 13, 2016 at 2:38 PM, Julien Valéry notifications@github.com wrote:

Hi, With dev mode there is no nodejs server behind, just a webpack "server" handler. In Readme, look for next section called DEV ONLY CLIENT/SERVER

— Reply to this email directly or view it on GitHub https://github.com/darul75/web-react/issues/20#issuecomment-171425590.

darul75 commented 8 years ago

I have to check tomorrow, but webpack dev server is listening on port 8081 but you node backend server is on 3000. can you try on 127.0.0.1:3000

darul75 commented 8 years ago

You need to run 2 process separitly on 2 prompts.

One with command :

npm run dev-server-client

( will run webpack server, rebundle when changes emitted ). Wait for this process to finish its work...about few seconds ;)

Then launch second: npm run dev-server

(starts your backend server)

Sorry on my phone right now

allannaranjo commented 8 years ago

Hi, thanks for replying: npm run dev-server-client twice?

Allan

On Wed, Jan 13, 2016 at 3:38 PM, Julien Valéry notifications@github.com wrote:

You need to run 2 process separitly on 2 prompts.

One with command :

npm run dev-server-client

( will run webpack server, rebundle when changes emitted ). Wait for this process to finish its work...about few seconds ;)

Then launch second: npm run dev-server-client

(starts your backend server)

Sorry on my phone right now

— Reply to this email directly or view it on GitHub https://github.com/darul75/web-react/issues/20#issuecomment-171442628.

allannaranjo commented 8 years ago

I imagine you mean:

npm run dev-server-debug

but I get:

Cannot find module '/**/build/server.js'

Any idea?

On Wed, Jan 13, 2016 at 3:40 PM, Allan Naranjo allan.naranjo@gmail.com wrote:

Hi, thanks for replying: npm run dev-server-client twice?

Allan

On Wed, Jan 13, 2016 at 3:38 PM, Julien Valéry notifications@github.com wrote:

You need to run 2 process separitly on 2 prompts.

One with command :

npm run dev-server-client

( will run webpack server, rebundle when changes emitted ). Wait for this process to finish its work...about few seconds ;)

Then launch second: npm run dev-server-client

(starts your backend server)

Sorry on my phone right now

— Reply to this email directly or view it on GitHub https://github.com/darul75/web-react/issues/20#issuecomment-171442628.

allannaranjo commented 8 years ago

I ran npm run build to be able to run "npm run dev-server" however the the build directory only has webpack.records.json and the script in package.json is: "dev-server": "node build/server.js", and since the build directory has no server.js I get:

Cannot find module '/build/server.js'. Any ideas? Regards,

Allan

On Wed, Jan 13, 2016 at 3:43 PM, Allan Naranjo allan.naranjo@gmail.com wrote:

I imagine you mean:

npm run dev-server-debug

but I get:

Cannot find module '/**/build/server.js'

Any idea?

On Wed, Jan 13, 2016 at 3:40 PM, Allan Naranjo allan.naranjo@gmail.com wrote:

Hi, thanks for replying: npm run dev-server-client twice?

Allan

On Wed, Jan 13, 2016 at 3:38 PM, Julien Valéry notifications@github.com wrote:

You need to run 2 process separitly on 2 prompts.

One with command :

npm run dev-server-client

( will run webpack server, rebundle when changes emitted ). Wait for this process to finish its work...about few seconds ;)

Then launch second: npm run dev-server-client

(starts your backend server)

Sorry on my phone right now

— Reply to this email directly or view it on GitHub https://github.com/darul75/web-react/issues/20#issuecomment-171442628.

allannaranjo commented 8 years ago

My issue is that everytime I make a change in the server I have to run, npm run build and then npm run start and it takes forever to do stuff.

On Wed, Jan 13, 2016 at 3:54 PM, Allan Naranjo allan.naranjo@gmail.com wrote:

I ran npm run build to be able to run "npm run dev-server" however the the build directory only has webpack.records.json and the script in package.json is: "dev-server": "node build/server.js", and since the build directory has no server.js I get:

Cannot find module '/build/server.js'. Any ideas? Regards,

Allan

On Wed, Jan 13, 2016 at 3:43 PM, Allan Naranjo allan.naranjo@gmail.com wrote:

I imagine you mean:

npm run dev-server-debug

but I get:

Cannot find module '/**/build/server.js'

Any idea?

On Wed, Jan 13, 2016 at 3:40 PM, Allan Naranjo allan.naranjo@gmail.com wrote:

Hi, thanks for replying: npm run dev-server-client twice?

Allan

On Wed, Jan 13, 2016 at 3:38 PM, Julien Valéry <notifications@github.com

wrote:

You need to run 2 process separitly on 2 prompts.

One with command :

npm run dev-server-client

( will run webpack server, rebundle when changes emitted ). Wait for this process to finish its work...about few seconds ;)

Then launch second: npm run dev-server-client

(starts your backend server)

Sorry on my phone right now

— Reply to this email directly or view it on GitHub https://github.com/darul75/web-react/issues/20#issuecomment-171442628 .

darul75 commented 8 years ago

hi, there was a regression in api.js file when exporting module

https://github.com/darul75/web-react/blob/a9edfb76a863e9ef1c4625a6e3c0558e357ea9bf/server/api/api.js

you can upgrade to 1.2.1 or get this code, it would fine then for hot reloading your changes in some cases, look at how webpack HMR works, for example it won't work for new route in express, that kind of stuff.