aboutsummaryrefslogtreecommitdiffstats
path: root/csci4131/hw7/index.js
diff options
context:
space:
mode:
authorRossTheRoss <mstrapp@protonmail.com>2021-05-16 21:38:59 -0500
committerRossTheRoss <mstrapp@protonmail.com>2021-05-16 21:38:59 -0500
commit9148fa6e2fad9d54e3451a4478e03f55f0a9fa3c (patch)
tree9e739b11361f5fd122b31cfce107947502b69809 /csci4131/hw7/index.js
parentAdd trash (diff)
downloadhomework-9148fa6e2fad9d54e3451a4478e03f55f0a9fa3c.tar
homework-9148fa6e2fad9d54e3451a4478e03f55f0a9fa3c.tar.gz
homework-9148fa6e2fad9d54e3451a4478e03f55f0a9fa3c.tar.bz2
homework-9148fa6e2fad9d54e3451a4478e03f55f0a9fa3c.tar.lz
homework-9148fa6e2fad9d54e3451a4478e03f55f0a9fa3c.tar.xz
homework-9148fa6e2fad9d54e3451a4478e03f55f0a9fa3c.tar.zst
homework-9148fa6e2fad9d54e3451a4478e03f55f0a9fa3c.zip
Rearrange files
Diffstat (limited to 'csci4131/hw7/index.js')
-rw-r--r--csci4131/hw7/index.js109
1 files changed, 0 insertions, 109 deletions
diff --git a/csci4131/hw7/index.js b/csci4131/hw7/index.js
deleted file mode 100644
index 851b096..0000000
--- a/csci4131/hw7/index.js
+++ /dev/null
@@ -1,109 +0,0 @@
-// YOU CAN USE THIS FILE AS REFERENCE FOR SERVER DEVELOPMENT
-const createError = require('http-errors');
-
-// Include the express module
-const express = require('express');
-
-// helps in extracting the body portion of an incoming request stream
-var bodyparser = require('body-parser');
-
-// Path module - provides utilities for working with file and directory paths.
-const path = require('path');
-
-// Helps in managing user sessions
-const session = require('express-session');
-
-// include the mysql module
-var mysql = require('mysql');
-
-// Bcrypt library for comparing password hashes
-const bcrypt = require('bcrypt');
-
-// Include the express router.
-const utilities = require('./api/utilities');
-
-const port = 9001;
-
-// create an express application
-const app = express();
-
-// Use express-session
-// In-memory session is sufficient for this assignment
-app.use(session({
- secret: "csci4131secretkey",
- saveUninitialized: true,
- resave: false
- }
-));
-
-// middle ware to serve static files
-app.use(express.static(path.join(__dirname, 'public')));
-
-// server listens on port for incoming connections
-app.listen(port, () => console.log('Listening on port', port));
-
-app.get('/', function (req, res) {
- res.sendFile(path.join(__dirname, 'public/welcome.html'));
-});
-
-// GET method route for the contacts page.
-// It serves contact.html present in public folder
-app.get('/contacts', function(req, res) {
- if(!req.session.user) {
- res.redirect('/login');
- } else {
- res.sendFile(path.join(__dirname, 'public/contacts.html'));
- }
-});
-
-app.get('/stocks', function(req, res) {
- res.redirect('/stock');
-})
-
-app.get('/stock', function (req, res) {
- if (!req.session.user) {
- res.redirect('/login');
- } else {
- res.sendFile(path.join(__dirname, 'public/stock.html'));
- }
-});
-
-app.get('/addContact', function (req, res) {
- if (!req.session.user) {
- res.redirect('/login');
- } else {
- res.sendFile(path.join(__dirname, 'public/addContact.html'));
- }
-});
-
-app.get('/login', function (req, res) {
- if (req.session.user) {
- res.redirect('/contacts');
- } else {
- res.sendFile(path.join(__dirname, 'login.html'));
- }
-});
-
-app.get('/logout', function(req, res) {
- res.redirect('/api/logout')
-});
-
-// Makes Express use a router called utilities
-app.use('/api', utilities);
-
-// function to return the 404 message and error to client
-app.use(function (req, res, next) {
- next(createError(404));
-});
-
-// error handler
-app.use(function (err, req, res, next) {
- // set locals, only providing error in development
- res.locals.message = err.message;
- res.locals.error = req.app.get('env') === 'development' ? err : {};
-
- // render the error page
- res.status(err.status || 500);
- // res.render('error');
- res.send();
-});