jaseew01 / multi-user-file-manager

0 stars 0 forks source link

Build API using Node Express #13

Closed jaseew01 closed 9 years ago

jaseew01 commented 9 years ago

I am still having problems hitting my post method from my browser. Just to make sure I am going about it the correct way, this is what I am doing:

  1. I open up the html file in my browser
  2. I start NodeServer.js from the command prompt
  3. I then hit the submit button on my form When I do this, none of the methods on my server are hit. I think I am just not understanding this correctly. Did I maybe create my form incorrectly?
skiadas commented 9 years ago

It is important how you open the file up in your browser. If you do it as a "file", so the location bar says something like: "file:///folders/path/to/the/file.html", then it's not going to work. You need to be accessing the file with the "localhost" thing, and the same port that your server is listening on. In particular, you need to adjust your server to make it serve that file on an "index.html" request.

If you are using Chrome and you open the Console and go to the Network tab, then when you refresh the page and try to submit etc it will show you what it's trying to do and why it failed. Might help zero in on the problem.

jaseew01 commented 9 years ago

Could you take a look at that commit that I just made? I am having trouble connecting to my SQLite Database. I am doing something wrong, and I haven't been able to figure out what it is.

skiadas commented 9 years ago

It's hard for me to troubleshoot that, as I cannot run mssql. Have you been able to pinpoint the error you are getting? Console.log every stage, especially around that connectDB function.

skiadas commented 9 years ago

So is your database sqlite or mssql?

jaseew01 commented 9 years ago

It is sqlite

skiadas commented 9 years ago

Ok then this might be the problem, as you are still using sql = require('mssql') which would presumably only work with a mssql database, so you probably need to instead get a module for sqlite. Do a google search for "sqlite node", should give you some hits, e.g. https://github.com/mapbox/node-sqlite3 if you're using sqlite3.

jaseew01 commented 9 years ago

got it, sorry I just assumed that the mssql package could be used for sqlite databases as well.

jaseew01 commented 9 years ago

Okay, with the last commit, I created a MySQL, not SQLite database. When I try and connect, the connection is timing out. The error is code: ETIMEOUT, the message is: failed to connect to JASEEW93: undefined in 1500ms. I have been messing with it for the past 24 hours and have made very little if not any progress on it. Any idea what is going on?

skiadas commented 9 years ago

That "undefined" part worries me a bit. Clearly isn't finding the database though. And I assume you were running the mssql server at the same time?

Are you sure you should be using "JASEEW93" as the "server name", rather than the local ip address?

Let's take a look at it tomorrow.

jaseew01 commented 9 years ago

Okay, sounds good.

jaseew01 commented 9 years ago

Can you take a look at app.get('file/:fileid/download, function...)? Is their a way to construct a file within this method to send back?

skiadas commented 9 years ago

Well a "file" is really nothing more than the contents of an HTTP request, with an appropriate MIME content type, I think. Look into MIME and the Content-Type attribute, it would essentially tell the browser how to handle the information it gets back. A little bit like how you get the JSON file now when you go to your start page? The browser just automatically downloads it instead of showing it to you.

jaseew01 commented 9 years ago

Okay, thanks I will take a look at that.