I am trying to deploy the following files after pushing and installing all necessary files but I keep getting the same application error page on Heroku. I am very new to web development, and am just lost. Any help is appreciated.
Index.js
<code>import express from 'express';
import bodyParser from 'body-parser';
import mysql from 'mysql';
import cors from 'cors';
import account from './account.js'
const app = express();
const db = mysql.createConnection({
host: 'database-3.c12ew6m4ku0j.us-east-2.rds.amazonaws.com',
user: 'root',
password: 'password',
database: 'calendrive'
});
const PORT = 3001;
db.connect(err => {
if (err) throw err;
console.log('Connected to the database');
});
app.use(cors());
// Setup CORS settings
app.use(cors({
// Required for sessions to work
// Will likely need changed on a production server
origin: ["http://localhost:8080", "http://localhost:8800"],
credentials: true
}));
app.use(express.json());
// Get all events
app.get('/events', (req, res) => {
db.query('SELECT * FROM events', (err, data) => {
if (err) return res.json(err);
return res.json(data);
});
});
// Add new event
app.post('/events', (req, res) => {
const values = [req.body.name, req.body.desc, req.body.address, req.body.start, req.body.end];
const q = "INSERT INTO events (`name`, `desc`, `address`, `start`, `end`) VALUES (?)";
db.query(q, [values], (err, data) => {
if (err) return res.json(err);
return res.json(data);
});
});
// Update event
app.put('/events/:id', (req, res) => {
const eventId = req.params.id;
const values = [req.body.name, req.body.desc, req.body.address, req.body.start, req.body.end];
const q = "UPDATE events SET `name` =?, `desc` =?, `address` =?, `start` =?, `end` =? WHERE id=?"
db.query(q, [...values, eventId], (err, result) => {
if (err) return res.json(err);
return res.json('Event updated');
});
});
// Delete event
app.delete('/events/:id', (req, res) => {
const eventId = req.params.id;
db.query('DELETE FROM events WHERE id=?', [eventId], (err, result) => {
if (err) throw err;
res.json('Event deleted');
});
});
account.setup(app);
// Start the backend HTTP server on port 8800
app.listen((process.env.PORT || PORT), () => {
console.log(`server running on PORT ${PORT}`);
});
</code>
<code>import express from 'express';
import bodyParser from 'body-parser';
import mysql from 'mysql';
import cors from 'cors';
import account from './account.js'
const app = express();
const db = mysql.createConnection({
host: 'database-3.c12ew6m4ku0j.us-east-2.rds.amazonaws.com',
user: 'root',
password: 'password',
database: 'calendrive'
});
const PORT = 3001;
db.connect(err => {
if (err) throw err;
console.log('Connected to the database');
});
app.use(cors());
// Setup CORS settings
app.use(cors({
// Required for sessions to work
// Will likely need changed on a production server
origin: ["http://localhost:8080", "http://localhost:8800"],
credentials: true
}));
app.use(express.json());
// Get all events
app.get('/events', (req, res) => {
db.query('SELECT * FROM events', (err, data) => {
if (err) return res.json(err);
return res.json(data);
});
});
// Add new event
app.post('/events', (req, res) => {
const values = [req.body.name, req.body.desc, req.body.address, req.body.start, req.body.end];
const q = "INSERT INTO events (`name`, `desc`, `address`, `start`, `end`) VALUES (?)";
db.query(q, [values], (err, data) => {
if (err) return res.json(err);
return res.json(data);
});
});
// Update event
app.put('/events/:id', (req, res) => {
const eventId = req.params.id;
const values = [req.body.name, req.body.desc, req.body.address, req.body.start, req.body.end];
const q = "UPDATE events SET `name` =?, `desc` =?, `address` =?, `start` =?, `end` =? WHERE id=?"
db.query(q, [...values, eventId], (err, result) => {
if (err) return res.json(err);
return res.json('Event updated');
});
});
// Delete event
app.delete('/events/:id', (req, res) => {
const eventId = req.params.id;
db.query('DELETE FROM events WHERE id=?', [eventId], (err, result) => {
if (err) throw err;
res.json('Event deleted');
});
});
account.setup(app);
// Start the backend HTTP server on port 8800
app.listen((process.env.PORT || PORT), () => {
console.log(`server running on PORT ${PORT}`);
});
</code>
import express from 'express';
import bodyParser from 'body-parser';
import mysql from 'mysql';
import cors from 'cors';
import account from './account.js'
const app = express();
const db = mysql.createConnection({
host: 'database-3.c12ew6m4ku0j.us-east-2.rds.amazonaws.com',
user: 'root',
password: 'password',
database: 'calendrive'
});
const PORT = 3001;
db.connect(err => {
if (err) throw err;
console.log('Connected to the database');
});
app.use(cors());
// Setup CORS settings
app.use(cors({
// Required for sessions to work
// Will likely need changed on a production server
origin: ["http://localhost:8080", "http://localhost:8800"],
credentials: true
}));
app.use(express.json());
// Get all events
app.get('/events', (req, res) => {
db.query('SELECT * FROM events', (err, data) => {
if (err) return res.json(err);
return res.json(data);
});
});
// Add new event
app.post('/events', (req, res) => {
const values = [req.body.name, req.body.desc, req.body.address, req.body.start, req.body.end];
const q = "INSERT INTO events (`name`, `desc`, `address`, `start`, `end`) VALUES (?)";
db.query(q, [values], (err, data) => {
if (err) return res.json(err);
return res.json(data);
});
});
// Update event
app.put('/events/:id', (req, res) => {
const eventId = req.params.id;
const values = [req.body.name, req.body.desc, req.body.address, req.body.start, req.body.end];
const q = "UPDATE events SET `name` =?, `desc` =?, `address` =?, `start` =?, `end` =? WHERE id=?"
db.query(q, [...values, eventId], (err, result) => {
if (err) return res.json(err);
return res.json('Event updated');
});
});
// Delete event
app.delete('/events/:id', (req, res) => {
const eventId = req.params.id;
db.query('DELETE FROM events WHERE id=?', [eventId], (err, result) => {
if (err) throw err;
res.json('Event deleted');
});
});
account.setup(app);
// Start the backend HTTP server on port 8800
app.listen((process.env.PORT || PORT), () => {
console.log(`server running on PORT ${PORT}`);
});
Package.json
<code>{
"name": "backend",
"version": "1.0.0",
"description": "CalenDrive backend server",
"main": "index.js",
"scripts": {
"start": "node index.js",
"devstart": "nodemon index.js"
},
"author": "CS350 Group 12",
"license": "ISC",
"dependencies": {
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"express": "^4.19.2",
"express-session": "^1.18.0",
"google-auth-library": "^9.7.0",
"mysql": "^2.18.1",
"nodemon": "^3.1.0"
}
}
</code>
<code>{
"name": "backend",
"version": "1.0.0",
"description": "CalenDrive backend server",
"main": "index.js",
"scripts": {
"start": "node index.js",
"devstart": "nodemon index.js"
},
"author": "CS350 Group 12",
"license": "ISC",
"dependencies": {
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"express": "^4.19.2",
"express-session": "^1.18.0",
"google-auth-library": "^9.7.0",
"mysql": "^2.18.1",
"nodemon": "^3.1.0"
}
}
</code>
{
"name": "backend",
"version": "1.0.0",
"description": "CalenDrive backend server",
"main": "index.js",
"scripts": {
"start": "node index.js",
"devstart": "nodemon index.js"
},
"author": "CS350 Group 12",
"license": "ISC",
"dependencies": {
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"express": "^4.19.2",
"express-session": "^1.18.0",
"google-auth-library": "^9.7.0",
"mysql": "^2.18.1",
"nodemon": "^3.1.0"
}
}
I’ve tried changing things around, commenting out some blocks, but I keep getting the same page. I also tried restarting the dynos and still got nothing.
New contributor
Logan Parish is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.