forked from GitDano007/Trader-Pro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
120 lines (90 loc) · 2.65 KB
/
Copy pathserver.js
File metadata and controls
120 lines (90 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Importing libraries
const express = require('express');
const app = express();
const exphbs = require('express-handlebars');
const path = require('path');
const request = require('request');
const bcrypt = require('bcrypt');
const bodyParser = require('body-parser');
const unirest = require('unirest');
const db = require("./models");
const mysql = require("mysql");
const PORT = process.env.PORT || 6807;
app.use(express.static("public"));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// Set Handlebars Middleware
app.engine('handlebars', exphbs({ defaultLayout: 'main' }));
app.set('view engine', 'handlebars');
if (process.env.JAWSDB_URL) {
connection = mysql.createConnection(process.env.JAWSDB_URL);
} else {
connection = mysql.createConnection({
host: "localhost",
port: 3306,
user: "root",
password: "password",
database: "trading_accountDB"
});
connection.connect(function(err) {
if (err) {
console.error("error connecting: " + err.stack);
return;
}
git });
};
app.get('/', function(req, res) {
res.render('index', {
test: request.body
});
});
app.use(express.json())
const users = []
app.get('/users', (req, res) => {
res.json(users)
})
app.post('/users', (req, res) => {
const user = {email: req.body.name, password: req.body.password}
users.push(user)
res.status(201).send()
});
app.get('/watchlist', (req, res) => {
db.All_stock.findAll({}).then((data) => {
const names = [];
for(let i = 0; i < data.length; i++) {
names.push({
id: data[i].dataValues.id,
name: data[i].dataValues.short_name
});
}
res.render('watchlist', { short_names: names });
})
});
app.get('/watchlist', (req, res) => {
db.All_stock.findOne({id: req.body.drop}).then((data) => {
const stocks = [];
for(let i = 0; i <data.length; i++) {
stocks.push({
id: data[i].dataValues.id,
name: data[i].dataValues.short_name,
symbol: data[i].dataValues.stock_symbol,
currentPrice: data[i].dataValues.stock_current_price,
dailyHigh: data[i].dataValues.stock_daily_high,
dailyLow: data[i].dataValues.stock_daily_low,
yearHigh: data[i].dataValues.stock_year_high,
yearLow: data[i].dataValues.stock_year_low
});
}
})
});
//routes
require("./routes/api_routes.js")(app);
require("./routes/homepage.js")(app);
require("./routes/all_stock_api_routes.js")(app);
require("./routes/users_api_routes.js")(app);
// Set static folder
app.use(express.static(path.join(__dirname, 'public')));
db.sequelize.sync({force: true}).then(() => {
app.listen(PORT, () => console.log('Server listening on: http://localhost:', + PORT))
})
//});