Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fullstack app #86

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
22 changes: 0 additions & 22 deletions .github/ISSUE_TEMPLATE.md

This file was deleted.

14 changes: 0 additions & 14 deletions .github/PULL_REQUEST_TEMPLATE.md

This file was deleted.

5 changes: 0 additions & 5 deletions .gitignore

This file was deleted.

11 changes: 0 additions & 11 deletions .nodemonignore

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ describe("Integration/unit testing app.js", function () {
const response = await request(app).get("/");
const { statusCode, text } = response;
expect(statusCode).toBe(200);
const titleDescription = `An API for interesting facts about numbers`;
expect(text).toContain(titleDescription);
});

test("GET request should call fact.getFact()", async () => {
const getFact = jest.spyOn(fact, "getFact");
const response = await request(app).get("/");
expect(getFact).toHaveBeenCalled();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ describe("non random routes", () => {
expect(res.text).toContain("January 8th");
});

test("invalid month/day form", async function () {
test("invalid month/day should redirect", async function () {
const res = await request(app).get("/2/3/math");
expect(res.statusCode).toBe(404);
expect(res.statusCode).toBe(302);
});

// tests for route "/:date([-0-9/.,]+)/:type(date)?"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions app.js → backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ console.log("\n\n\n=== ##### STARTING SERVER ##### ===\nat", new Date(), "\n");

// Module dependencies.
const fs = require("fs");
const path = require('path');
const express = require("express");
const https = require("https");
const _ = require("underscore");
Expand Down Expand Up @@ -108,7 +109,7 @@ app.use(
app.use(express.json());
// app.set("views", __dirname + "/views");
app.enable("jsonp callback");
app.use(express.static("public"));
app.use(express.static(path.join(__dirname, "../frontend", "build")));
app.use(express.urlencoded({ extended: false }));
app.use(
favicon(__dirname + "/public/img/favicon.png", {
Expand All @@ -120,12 +121,7 @@ if (nodeEnv === "development") {
app.use(errorhandler());
}

// Routes
app.use("/", numRoutes);

// TODO: Precompile this template.
// Route that renders the home page html
// source is ./README.md
app.get("/", function (req, res) {
var currDate = new Date();
res.render("index.html", {
Expand All @@ -148,6 +144,10 @@ app.get("/", function (req, res) {
});
});

app.use((req, res, next) => {
res.redirect('/');
});

app.use("/js", express.static(__dirname + "/node_modules/jquery-mousewheel"));

module.exports = app;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions backend/suggestions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{"trivia":true,"number":5,"fact":"5 is an odd number"}
{"trivia":true,"number":5,"fact":"5 is an odd number"}
{"trivia":true,"number":5,"fact":"5 is an odd number"}
{"trivia":true,"number":5,"fact":"5 is an odd number"}
{"trivia":true,"number":5,"fact":"5 is an odd number"}
{"trivia":true,"number":5,"fact":"5 is an odd number"}
{"trivia":true,"number":5,"fact":"5 is an odd number"}
File renamed without changes.
23 changes: 23 additions & 0 deletions facts-dump/date.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
1
the Julian calendar takes effect for the first time
the Roman Senate posthumously deifies Julius Caesar
the Roman legions in Germania Superior refuse to swear loyalty to Galba

60
Christopher Columbus uses his knowledge of a lunar eclipse that night to convince Native Americans to provide him with supplies
February 29 is followed by February 30 in Sweden, in a move to abolish the Swedish calendar for a return to the Old style

348
is Taylor Swift's birthday in 1989
in 1577 that Sir Francis Drake sets out from Plymouth, England, on his round-the-world voyage.

364
the USS Constitution under the command of Captain William Bainbridge, captures the HMS Java off the coast of Brazil after a three hour battle
the Treaty of New Echota is signed, ceding all the lands of the Cherokee east of the Mississippi River to the United States
the first American YMCA opens in Boston, Massachusetts

-Infinity
negative infinity

Infinity
infinity
17 changes: 17 additions & 0 deletions facts-dump/math.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
0
0

1
the multiplicative identity
the first figurate number of every kind, such as triangular number, pentagonal number and centered hexagonal number, to name just a few
also the first and second numbers in the Fibonacci sequence and is the first number in many other mathematical sequences
the most common leading digit in many sets of data, a consequence of Benford's law

2010
the number of trees on 15 vertices with diameter 7

-Infinity
negative infinity

Infinity
infinity
1 change: 1 addition & 0 deletions facts-dump/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello world
14 changes: 14 additions & 0 deletions facts-dump/trivia.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
0
0

1
the number of Gods in monotheism
the number of dimensions of a line
the number of moons orbiting Earth
the loneliest number

-Infinity
negative infinity

Infinity
infinity
21 changes: 21 additions & 0 deletions facts-dump/year.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
0
0

1
Amanishakheto, Queen of Kush (Nubia), dies
the Teotihuacan culture in Mesoamerica begins (approximate date)
the poem Metamorphoses is written by Ovid
Livy writes his monumental History of Rome (Ab Urbe Condita)

2010
the tallest man-made structure to date, the Burj Khalifa in Dubai, United Arab Emirates, is officially opened
the Togo national football team is involved in an attack in Angola, and as a result withdraws from the Africa Cup of Nations

-1225
stuff happened

-Infinity
negative infinity

Infinity
infinity
23 changes: 23 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
22 changes: 22 additions & 0 deletions frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Numbers API
***

### Frontend development setup :

The backend and frontend are in the same directory and are deployed together. When working in development mode on the frontend React App, both the backend and frontend need to be running.
```
cd /backend
npm run start
```
```
cd /frontend
npm run start
```
This allows you to see any changes being made to the frontend during development.
The backend serves a single static file to the client that is pointed to the current build of the react app.
Running 'npm run build' from the frontend transpiles the React code into a static html file.
The server will serve this static file in deployment.

***


Loading