christianalfoni / webpack-express-boilerplate

A boilerplate for running a Webpack workflow in Node express
MIT License
1.39k stars 291 forks source link

Adding server js files to get stuff from database? #23

Closed henrikra closed 8 years ago

henrikra commented 8 years ago

Hello

Is it possible to add example on how can I add api routes where I can get data from database form example? I tried to add app.get('/api/lol', function response(req, res) { res.write("looooooooooool"); }); to server.js and call it with jQuery $.get('/api/lol', function(result) { console.log(result); }); but Im not getting anything back.

henrikra commented 8 years ago

I think this has to be something with app.get('*', function response ?

christianalfoni commented 8 years ago

That should work, but you have to add it at the top. Right after const app = express() :-)

henrikra commented 8 years ago

Thank you jesus! It worked :D

christianalfoni commented 8 years ago

If you look a bit further down you see a app.get('*'..., this one picks up all get requests. Any get routes defines after it will never be checked :-) That is the reason

henrikra commented 8 years ago

Thank you for explanation!