From d2f4e3f45cc15922d4d0e1f442675e66887a7a42 Mon Sep 17 00:00:00 2001 From: gickers Date: Fri, 26 Jan 2024 15:23:23 +0000 Subject: [PATCH] rossco changes --- axiosdemo.js | 12 ++++++++++++ dbdemoapp.js | 29 +++++++++++++++++++++++++++++ dbhelp.js | 14 ++++++++++++++ dieroll.js | 25 +++++++++++++++++++++++++ html/about.html | 16 ++++++++++++++++ html/nolansite.html | 42 ++++++++++++++++++++++++++++++++++++++++++ jsonapp.js | 9 +++++++++ rosscoapp.js | 13 +++++++++++++ rosscoserver.js | 21 +++++++++++++++++++++ 9 files changed, 181 insertions(+) create mode 100644 axiosdemo.js create mode 100644 dbdemoapp.js create mode 100644 dbhelp.js create mode 100644 dieroll.js create mode 100644 html/about.html create mode 100644 html/nolansite.html create mode 100644 jsonapp.js create mode 100644 rosscoapp.js create mode 100644 rosscoserver.js diff --git a/axiosdemo.js b/axiosdemo.js new file mode 100644 index 00000000..0a243276 --- /dev/null +++ b/axiosdemo.js @@ -0,0 +1,12 @@ + +const axios = require("axios").default; + +const url = "http://localhost:3000/"; + +const resultingPromise = axios.get(url); + +resultingPromise.then(printLogResultsOfGet); + +function printLogResultsOfGet(result) { + console.log(result.data); +} \ No newline at end of file diff --git a/dbdemoapp.js b/dbdemoapp.js new file mode 100644 index 00000000..edbc1bf0 --- /dev/null +++ b/dbdemoapp.js @@ -0,0 +1,29 @@ +const express = require('express'); + +const { makeDBConnectionPool } = require("./dbhelp"); + +const pool = makeDBConnectionPool("omdb"); + +const app = express(); + +let movieList = [] + +app.listen(3000) + +app.get('/',(request, response) =>{ + response.json(movieList); +}); + +function displayMovies(movieRows) { + for (let row of movieRows) { + movieList.push(row.movie_name); + } + return movieList; +} +function arrayofMovies(){ + pool.query("select movie_name from casts_view where person_name = 'Tom Hardy'").then((results) => { + displayMovies(results.rows); + }); +} + +arrayofMovies(); \ No newline at end of file diff --git a/dbhelp.js b/dbhelp.js new file mode 100644 index 00000000..9b3c6e36 --- /dev/null +++ b/dbhelp.js @@ -0,0 +1,14 @@ +const { Pool } = require("pg"); + +/** + *Makes a pool of connections to the named database. it is assumed the db is on localhost. + * @param {string} dbName name of database to connect to + */ +function makeDBConnectionPool(dbName) { + //Understanding the details is not important here. + return new Pool({ + database: dbName, + }); +} + +module.exports = { makeDBConnectionPool }; \ No newline at end of file diff --git a/dieroll.js b/dieroll.js new file mode 100644 index 00000000..11a7f41a --- /dev/null +++ b/dieroll.js @@ -0,0 +1,25 @@ +const express = require('express'); + +const app = express(); + +app.listen(3000) + +app.get('/roll1',(request, response) =>{ + response.send('Your dice roll is:' + randomDieRoll1()) +}); + +app.get('/roll2',(request, response) =>{ + response.send('Your dice roll is:' + totalDiceRoll()) +}); + +function randomDieRoll1(){ + return 1 + Math.floor((Math.random() * 6)) +} + +function randomDieRoll2(){ + return 1 + Math.floor((Math.random() * 6)) +} + +function totalDiceRoll(){ + return randomDieRoll1() + randomDieRoll2() +} \ No newline at end of file diff --git a/html/about.html b/html/about.html new file mode 100644 index 00000000..450105c1 --- /dev/null +++ b/html/about.html @@ -0,0 +1,16 @@ + + + +
+ <
+
+ +

About Me

+

About Me Page

+ + + + +
+ + \ No newline at end of file diff --git a/html/nolansite.html b/html/nolansite.html new file mode 100644 index 00000000..3b88a3a8 --- /dev/null +++ b/html/nolansite.html @@ -0,0 +1,42 @@ + + + +
+

Previous Site

+

Next Site

+
+
+ +

Christopher Nolan

+

The worlds Greatest Director?

+
+ Christopher Nolan in a tux +
+ Christopher Nolan attending a premiere of one of his films. +
+
+
+

Here is a list of Christopher Nolan's films

+
    +
  • Memento (2000)
  • +
  • Batman Begins (2005)
  • +
  • The Presige (2006)
  • +
  • The Dark Knight (2008)
  • +
  • Inception (2010)
  • +
  • The Dark Knight Rises (2012)
  • +
  • Interstellar (2014)
  • +
  • Dunkirk (2017)
  • +
  • Tenet (2020)
  • +
  • Oppenheimer (2023)
  • +

    I find it very hard to chose favouorite films but in the interests of making this website I will give my top 3 Christopher Nolan films in order.

    +
      +
    1. Batman Begins - the re-birth of the Batman franchise this film was cooler than cool.
    2. +
    3. The Dark Knight - Heath Ledger as the Joker, enough said.
    4. +
    5. Inception - am I dreaming? No this is just the best Nolan film to date.
    6. +
    +

    Find out more about Christpoher Nolan from this link

    + + +
+ + \ No newline at end of file diff --git a/jsonapp.js b/jsonapp.js new file mode 100644 index 00000000..86d796e9 --- /dev/null +++ b/jsonapp.js @@ -0,0 +1,9 @@ +const express = require('express'); + +const app = express(); + +app.listen(3000) + +app.get('/',(request, response) =>{ + response.json(['ross','lauren','neill']) +}); \ No newline at end of file diff --git a/rosscoapp.js b/rosscoapp.js new file mode 100644 index 00000000..420259b6 --- /dev/null +++ b/rosscoapp.js @@ -0,0 +1,13 @@ +const express = require('express'); + +const app = express(); + +app.listen(3000) + +app.get('/',(request, response) =>{ + response.sendFile('./html/nolansite.html', { root: __dirname}); +}); + +app.get('/about',(request, response) =>{ + response.sendFile('./html/about.html', { root: __dirname}); +}); \ No newline at end of file diff --git a/rosscoserver.js b/rosscoserver.js new file mode 100644 index 00000000..f5550ab8 --- /dev/null +++ b/rosscoserver.js @@ -0,0 +1,21 @@ +const http = require("http"); +const fs = require("fs"); + +const server = http.createServer((request, result) => { + console.log("request made"); + result.setHeader("Content-Type", "text/html"); + + fs.readFile("./html/nolansite.html", (error, data) => { + if (error) { + console.log(error); + result.end(); + } else { + result.write(data); + result.end(); + } + }); +}); + +server.listen(3000, "localhost", () => { + console.log("listening for requests"); +});