Guest User

Untitled

a guest
Jan 11th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. const app = require('./config/server')
  2.  
  3. // port must be set to 9095 because incoming http requests are routed from port 80 to port 9095
  4. app.listen(9095, function () {
  5. console.log('Node app is running on port 9095');
  6. });
  7.  
  8. const express = require('express');
  9. const consign = require('consign')
  10. const bodyParser = require('body-parser');
  11. const cors = require('cors');
  12.  
  13. const corsOptions = {
  14. origin: 'http://localhost:4200',
  15. optionsSuccessStatus: 200
  16. }
  17.  
  18. const app = express();
  19.  
  20. app.use(bodyParser.urlencoded({ extended: true }));
  21. app.use(bodyParser.json());
  22. app.use(cors(corsOptions))
  23.  
  24. consign()
  25. .include('app/routes')
  26. .then('config/dbConnection.js')
  27. .then('app/models')
  28. .then('app/controllers')
  29. .into(app);
  30.  
  31. module.exports = app;
  32.  
  33. const mysql = require('mysql')
  34.  
  35. const connMySQL = () => {
  36. return mysql.createConnection({
  37. host: 'localhost',
  38. user: 'root',
  39. password: 'eqix1998',
  40. database: 'quotedb',
  41. port: 3306
  42. });
  43. }
  44.  
  45. module.exports = () => {
  46. return connMySQL;
  47. }
  48.  
  49. module.exports = (application) => {
  50. application.get('/quotes', (req, res) => {
  51. application.app.controllers.quotes.quotes(application, req, res);
  52. });
  53. }
  54.  
  55. module.exports.quotes = (application, req, res) => {
  56. var connection = application.config.dbConnection();
  57. var quotesDAO = new application.app.models.QuotesDAO(connection);
  58.  
  59. quotesDAO.getQuotes((error, results) => {
  60. res.send(results)
  61. });
  62. }
  63.  
  64. function QuotesDAO(connection){
  65. this._connection = connection;
  66. console.log(this._connection)
  67. }
  68.  
  69. QuotesDAO.prototype.getQuotes = (callback) => {
  70. this._connection.query('SELECT * FROM quotes', callback)
  71. }
  72.  
  73. module.exports = () => {
  74. return QuotesDAO;
  75. }
Add Comment
Please, Sign In to add comment