Compare commits

..

No commits in common. "0327b36031a9da9b6cef4c22fa860de710044997" and "f5df0442ed12bc6103d61e90d377a2a55fdd3508" have entirely different histories.

3 changed files with 778 additions and 1519 deletions

View File

@ -1,56 +1,18 @@
const express = require("express"); const express = require('express')
const app = express(); const app = express()
const cors = require("cors"); const cors = require('cors')
const mongoose = require("mongoose"); require('dotenv').config()
require("dotenv").config();
const PORT = process.env.PORT || 16749; app.use(cors())
const MONGODB_URI = process.env.MONGODB_URI || ""; app.use(express.static('public'))
app.get('/', (req, res) => {
mongoose.connect(MONGODB_URI, { res.sendFile(__dirname + '/views/index.html')
// @ts-ignore
useNewUrlParser: true,
useUnifiedTopology: true,
}); });
const exerciseLogsSchema = new mongoose.Schema({
username: { type: String, required: true },
log: [
{
description: { type: String, required: true },
duration: { type: Number, required: true },
date: { type: String, required: true },
},
],
});
const exerciseLogs = mongoose.model("ExerciseLogs", exerciseLogsSchema);
app.use(cors());
app.use(express.static("public"));
app.use(express.urlencoded({ extended: false }));
app.get("/", (req, res) => {
res.sendFile(__dirname + "/views/index.html");
});
app.post("/api/users", (req, res) => {
const username = req.body.username; const listener = app.listen(process.env.PORT || 3000, () => {
const exerciseLogsModel = new exerciseLogs({ username: username }); console.log('Your app is listening on port ' + listener.address().port)
exerciseLogsModel
.save()
.then((user) => {
if (user) return res.json({ username: user.username, _id: user._id });
res.status(500);
res.json({ error: `Error creating user: ${username}` });
}) })
.catch((err) => {
res.status(500);
return res.json({
error: `Error type 2 while creating user: ${username}`,
});
});
});
const listener = app.listen(PORT, () => {
console.log("Your app is listening on port " + listener.address().port);
});

1112
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
{ {
"name": "@radii-fcc-backend/fcc-exercise-tracker", "name": "fcc-exercise-tracker",
"version": "0.1.0", "version": "0.1.0",
"description": "A REST API project, part of Free Code Camp's curriculum", "description": "A REST API project, part of Free Code Camp's curriculum",
"main": "index.js", "main": "index.js",
@ -7,15 +7,14 @@
"start": "node index.js" "start": "node index.js"
}, },
"dependencies": { "dependencies": {
"cors": "^2.8.5",
"dotenv": "^8.2.0", "dotenv": "^8.2.0",
"express": "^4.16.4", "express": "^4.16.4",
"mongoose": "^7.0.3" "cors": "^2.8.5"
}, },
"repository": { "repository": {
"url": "https://github.com/freeCodeCamp/boilerplate-project-exercisetracker" "url": "https://github.com/freeCodeCamp/boilerplate-project-exercisetracker"
}, },
"license": "AGPL-3.0-or-later", "license": "MIT",
"keywords": [ "keywords": [
"node", "node",
"express" "express"