Changed url to be read from env_variables.

This commit is contained in:
Kevin Midboe
2017-04-12 22:15:36 +02:00
parent 2a66ab7b9a
commit 4704259bc9
2 changed files with 3 additions and 87 deletions

View File

@@ -1,85 +0,0 @@
// server.js
// BASE SETUP
// =============================================================================
// call the packages we need
var express = require('express'); // call express
var app = express(); // define our app using express
var bodyParser = require('body-parser');
var sqlite3 = require('sqlite3').verbose();
// configure app to use bodyParser()
// this will let us get the data from a POST
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
var port = 31459; // set our port
// ROUTES FOR OUR API
// =============================================================================
var router = express.Router(); // get an instance of the express Router
// test route to make sure everything is working (accessed at GET http://localhost:8080/api)
router.get('/', function(req, res) {
res.json({ message: 'hooray! welcome to our api!' });
});
router.get('/seasoned', function(req, res) {
var db_path = 'shows.db';
var db = new sqlite3.Database(db_path);
var returnMsg;
var id = req.param('id');
function getEpisode(id, fn){
db.serialize(function() {
db.get("SELECT * FROM stray_eps WHERE id = '" + id + "'", function(err, row) {
fn(row)
})
});
db.close();
}
getEpisode(id, function(episode){
res.setHeader('Access-Control-Allow-Origin', 'https://kevinmidboe.com');
res.json({episode}); // this is where you get the return value
});
});
router.post('/seasoned', function (req, res) {
console.log(req.body['id']);
var db_path = 'shows.db';
var db = new sqlite3.Database(db_path);
var UPDATE_DATA = "UPDATE stray_eps SET verified=$verified WHERE id=$id";
db.serialize(function() {
// var stmt = db.prepare("UPDATE stray_eps SET verified=? WHERE id=?");
// for (key in req.body) {
// stmt.run(req.body[key]);
// console.log(req.body[key]);
// }
db.run(UPDATE_DATA, {$verified: req.body['verified'], $id: req.body['id']}, function(err) {
if (err) {
console.log(err);
} else {
console.log('UPDATE DATA');
}
});
// stmt.run([req.body['verified'], req.body['id']]);
// stmt.finalize();
db.close();
});
res.setHeader('Access-Control-Allow-Origin', 'https://kevinmidboe.com');
res.json({message: 'updated'});
})
// more routes for our API will happen here
// REGISTER OUR ROUTES -------------------------------
// all of our routes will be prefixed with /api
app.use('/api', router);
// START THE SERVER
// =============================================================================
app.listen(port);
console.log('Magic happens on port ' + port);

View File

@@ -1,3 +1,4 @@
function getURLId() {
var sPageURL = window.location.search.substring(1);
var sParameterName = sPageURL.split('=');
@@ -30,7 +31,7 @@ $("#searchForm").submit(function(e) {
formJsonObj['id'] = getURLId();
console.log(formJsonObj);
var url = 'https://apollo.kevinmidboe.com/api/seasoned';
var url = env_variables.url;
$.ajax({
url: url,
dataType: 'json',
@@ -57,7 +58,7 @@ function foo(id) {
}
function getShow() {
var url = 'https://apollo.kevinmidboe.com/api/seasoned?id=' + getURLId();
var url = env_variables.url + '?id=' + getURLId();
$.ajax({
url: url,
dataType: "json",