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

Unable to add Express REST API #24

Closed
sravikiran opened this issue Jun 22, 2015 · 5 comments
Closed

Unable to add Express REST API #24

sravikiran opened this issue Jun 22, 2015 · 5 comments

Comments

@sravikiran
Copy link

Hi,

I just started playing with this starter kit. I ran the sample using the following command to make use of the express-server-example.js file:

node server/express-server-example

It starts the server on the port 8080 and I am able to browse the sample. Then I added the following REST endpoint to the file express-server-example.js:

app.get('/api/sample', function(request, response) {
response.send({name:"Ravi"});
});

Now when I hit this endpoint, I get the following view instead of getting JSON response from the endpoint:

image

I tried to fix this and ended with no luck as of now. Is this a bug in the starter kit? Otherwise, can someone help me in resolving this?

@PatrickJS
Copy link
Owner

this is due to the order of the middleware and WebpackDevServer having historyAPiFallback

@PatrickJS
Copy link
Owner

I updated the server stub and turned off historyApiFallback from the devServer and included a todo api example for you to start from. If you have anymore questions you can comment here or open another issue thanks!

@sravikiran
Copy link
Author

@gdi2290 Thanks Patrick. I tried it and it worked well. I have just one more question, how to run the express server along with the build and watch processes? I tried it with the following script in NPM, but it stops at express and doesn't run watch:

"myServer": "npm install && npm run build && npm run express && npm run watch"

Is there a way to run both of them together?

@PatrickJS
Copy link
Owner

@sravikiran the stub is rebuilding in development but you have to reload manually express-server-example.js#L97 until I correctly inject the webpack socketio stuff. I would delete the build folder and run npm run express then reload the browser manually when you make a change for now. You don't need to use npm run build or npm run watch with the express stub since the files are built in-memory

@sravikiran
Copy link
Author

@gdi2290 Thanks again for the response. That makes sense.

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

2 participants