-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7582a14
commit 99f4387
Showing
29 changed files
with
17,450 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "reacttemplate", | ||
"version": "0.1.0", | ||
"private": true, | ||
"proxy": "http://localhost:3001/", | ||
"dependencies": { | ||
"react": "^16.6.3", | ||
"react-dom": "^16.6.3", | ||
"react-scripts": "^2.1.1", | ||
"react-router-dom": "^4.3.1", | ||
"axios": "^0.18.0" | ||
}, | ||
"scripts": { | ||
"start": "react-scripts start", | ||
"build": "react-scripts build", | ||
"test": "react-scripts test --env=jsdom", | ||
"eject": "react-scripts eject" | ||
} | ||
} |
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const db = require("../models"); | ||
|
||
module.exports = { | ||
findAll: function(req, res) { | ||
db.Test | ||
.find(req.query) | ||
.sort({ date: -1 }) | ||
.then(dbModel => res.json(dbModel)) | ||
.catch(err => res.status(422).json(err)); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const mongoose = require('mongoose'); | ||
require("dotenv").config(); | ||
|
||
const handleError = e => { | ||
console.error(`Mongoose connection error: ${JSON.stringify(e)}`); | ||
} | ||
|
||
const options = { | ||
useNewUrlParser: true, | ||
autoReconnect: true | ||
} | ||
|
||
const connect = (URI) => | ||
mongoose.connect(URI || process.env.MONGODB_URI, options) | ||
.catch(handleError); | ||
|
||
mongoose.connection.on('error', handleError); | ||
mongoose.connection.on('connecting', () => console.info('Starting to make initial connection to the MongoDB server...')); | ||
mongoose.connection.on('connected', () => console.info('Mongoose successfully connected to MongoDB server.')); | ||
mongoose.connection.on('disconnecting', () => console.warn('Mongoose is disconnecting from the MongoDB server...')); | ||
mongoose.connection.on('disconnected', () => console.warn('Mongoose lost connection to the MongoDB server. This may be due to an expected connection close, the database server crashing, or network connectivity issues.')); | ||
mongoose.connection.on('reconnected', () => console.info('Mongoose successfully reconnected to MongoDB server.')); | ||
mongoose.connection.on('reconnectFailed', () => console.error('Mongoose was unable to successfully reconnect to MongoDB server. No further attempts will be made.')); | ||
|
||
module.exports = connect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
Test: require("./test") | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const mongoose = require("mongoose"); | ||
const Schema = mongoose.Schema; | ||
|
||
const testSchema = new Schema({ | ||
title: { type: String, required: true }, | ||
date: { type: Date, default: Date.now } | ||
}); | ||
|
||
const Test = mongoose.model("Test", testSchema); | ||
|
||
module.exports = Test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const router = require("express").Router(); | ||
const testRoutes = require("./test"); | ||
|
||
router.use("/test", testRoutes); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const router = require("express").Router(); | ||
const testController = require("../../controllers/testController"); | ||
|
||
router | ||
.route("/") | ||
.get(testController.findAll) | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const path = require("path"); | ||
const router = require("express").Router(); | ||
const apiRoutes = require("./api"); | ||
|
||
router.use("/api", apiRoutes); | ||
|
||
router.use((req, res) => { | ||
res.sendFile(path.join(__dirname, "../client/build/index.html")); | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require("../dbconfig/connection.js")(); | ||
const db = require("../models"); | ||
|
||
const randomHour = () => 3600000*(Math.random() * (10 - 1) + 1); | ||
const seed = [ | ||
{ | ||
title: "Test 1", | ||
date: new Date(Date.now() + randomHour) | ||
}, | ||
{ | ||
title: "Test 2", | ||
date: new Date(Date.now() + randomHour) | ||
}, | ||
{ | ||
title: "Test 3", | ||
date: new Date(Date.now() + randomHour) | ||
} | ||
]; | ||
|
||
db.Test | ||
.remove({}) | ||
.then(() => db.Test.collection.insertMany(seed)) | ||
.then(data => { | ||
console.log(data.result.n + " records inserted!"); | ||
process.exit(0); | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const express = require("express"); | ||
const routes = require("./routes"); | ||
const server = express(); | ||
const PORT = process.env.PORT || 3001; | ||
const mongooseConnect = require("./dbconfig/connection.js"); | ||
|
||
server.use(express.urlencoded({ extended: true })); | ||
server.use(express.json()); | ||
|
||
if (process.env.NODE_ENV === "production") | ||
server.use(express.static("client/build")); | ||
|
||
server.use(routes); | ||
|
||
server.listen(PORT, () => { | ||
console.log(`Server running on PORT ${PORT}!`); | ||
mongooseConnect(); | ||
}); |
Oops, something went wrong.