Skip to content

Commit

Permalink
fixed CORS issues
Browse files Browse the repository at this point in the history
  • Loading branch information
beatface committed Mar 18, 2016
1 parent 3edf7f2 commit 259f7ed
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 30 deletions.
5 changes: 1 addition & 4 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@
"esversion": 6,
"strict": true,
"esnext": false,
"node": true,
"predef": [
"app"
]
"node": true
}
18 changes: 1 addition & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
# dashbored

Dashbored is an all-in-one dashboard for users to keep notes, track the weather, get news updates, etc. Built with Express, Angular, Node, and SQLite.
Dashbored is an all-in-one dashboard for users to keep notes, track the weather, get news updates, etc. Built with Electron, Express, Angular, Node, and SQLite. This repo represents the server-side API.

### Purpose
This app was written for my back-end capstone at [Nashville Software School](http://nashvillesoftwareschool.com/).

### Features


### Local Use
If you want to run this app locally/get it on your machine -
1. Git clone onto your local machine/repository(via HTTPS) - ``` git clone https://github.com/beatface/dashbored.git```
2. Go into the new cloned directory - ``` cd dashbored ```
3. Install packages required by this app -
```
npm install
```
4. Run express server, and you're done! (after running, go to localhost:8896 in your browser to view) -
```
npm start
```
10 changes: 6 additions & 4 deletions models/notes_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ module.exports.index = (req, res) => {
ON Notes.userid = UserData.userid
WHERE Notes.userid = UserData.userid;`, (err, data) => {
if (err) throw err;
console.log("the data coming back!", data);
// console.log("the data coming back!", data);
res.send(data);
});
};

module.exports.postNote = (req, res) => {
console.log(req.body);
// add the new note to the database
let title = req.body.title;
let note = req.body.content;
db.run(`INSERT INTO Notes VALUES (NULL, "${title}", "${note}", 1)`, (err) => {
if (err) throw err;
res.redirect('/');
res.send('success!');
});
};

Expand All @@ -47,8 +48,9 @@ module.exports.destroyNote = (req, res) => {
};

module.exports.update = (req, res) => {
let title = req.body.title;
let note = req.body.content;
console.log(">>>>>>>>>>>>>>>>>>>>>>", req.body);
const title = req.body.title;
const note = req.body.content;
// update specific note
db.run(`UPDATE Notes
SET Notes.Title = '${title}', Notes.Content = '${note}'
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"homepage": "https://github.com/beatface/dashbored#readme",
"dependencies": {
"body-parser": "^1.15.0",
"cors": "^2.7.1",
"electron-connect": "^0.3.7",
"electron-prebuilt": "^0.36.10",
"express": "^4.13.4",
Expand Down
4 changes: 0 additions & 4 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
const express = require('express');
const router = express.Router();

// const sqlite3 = require('sqlite3');
// const db = new sqlite3.Database('./db/dashbored.sqlite');

const notes = require('./notes_routes.js');

router.use(notes);


module.exports = router;
2 changes: 1 addition & 1 deletion routes/notes_routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ router.get('/notes', ctrl.index);
router.post('/notes', ctrl.postNote);
router.get('/notes/:id', ctrl.showNote);
router.delete('/notes/:id', ctrl.destroy);
router.put('/notes/:id', ctrl.update);
router.post('/notes/:id', ctrl.update);

module.exports = router;
4 changes: 4 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const cors = require('cors');
const app = express();
const PORT = process.env.PORT || 3153;

// Express routes, views, ctrls
const routes = require('./routes/');
app.use(cors());
app.use(bodyParser.json());

app.use(routes);

Expand Down

0 comments on commit 259f7ed

Please sign in to comment.