Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const app = require('./config/server')
- // port must be set to 9095 because incoming http requests are routed from port 80 to port 9095
- app.listen(9095, function () {
- console.log('Node app is running on port 9095');
- });
- const express = require('express');
- const consign = require('consign')
- const bodyParser = require('body-parser');
- const cors = require('cors');
- const corsOptions = {
- origin: 'http://localhost:4200',
- optionsSuccessStatus: 200
- }
- const app = express();
- app.use(bodyParser.urlencoded({ extended: true }));
- app.use(bodyParser.json());
- app.use(cors(corsOptions))
- consign()
- .include('app/routes')
- .then('config/dbConnection.js')
- .then('app/models')
- .then('app/controllers')
- .into(app);
- module.exports = app;
- const mysql = require('mysql')
- const connMySQL = () => {
- return mysql.createConnection({
- host: 'localhost',
- user: 'root',
- password: 'eqix1998',
- database: 'quotedb',
- port: 3306
- });
- }
- module.exports = () => {
- return connMySQL;
- }
- module.exports = (application) => {
- application.get('/quotes', (req, res) => {
- application.app.controllers.quotes.quotes(application, req, res);
- });
- }
- module.exports.quotes = (application, req, res) => {
- var connection = application.config.dbConnection();
- var quotesDAO = new application.app.models.QuotesDAO(connection);
- quotesDAO.getQuotes((error, results) => {
- res.send(results)
- });
- }
- function QuotesDAO(connection){
- this._connection = connection;
- console.log(this._connection)
- }
- QuotesDAO.prototype.getQuotes = (callback) => {
- this._connection.query('SELECT * FROM quotes', callback)
- }
- module.exports = () => {
- return QuotesDAO;
- }
Add Comment
Please, Sign In to add comment