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

API Routes Buildout Part 1: Users #4

Open
wants to merge 1 commit 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*/.DS_Store
node_modules
.env
package-lock.json
package-lock.json
*.js~
*.js.un~
29 changes: 26 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const express = require("express");
const schema = require(__dirname + "/schema.js");
const security = require(__dirname + "/securityFunctions.js");
const app = express();
const mongoose = require('mongoose');

function closeServer (serverToClose) {
serverToClose.close(() => {
Expand All @@ -16,8 +17,8 @@ function closeServer (serverToClose) {

let server = app.listen(process.env.PORT, () => {
console.log("Started listening at port " + process.env.PORT);
console.log(schema);
console.log(security);
//console.log(schema.User);
//console.log(security);
if (process.argv[2] === "build") {
setTimeout(() => {
closeServer(server);
Expand All @@ -29,8 +30,30 @@ app.get("/", (req, res) => {
res.send("Welcome to the KSDT API");
});

/* This endpoint is a directory for all registerd KSDT users */
app.get("/users/", (req, res) => {
User.find({}, function(err, users) {
if (err) {
console.log("Error!");
} else {
//We send the user query to view "users"
res.render("users", {users: user});

console.log(users);
}
})
res.send("This is the User Directory Page");
});

app.get("/users/:userID", (req, res) => {
res.send("Testing!");
User.findById(req.params.id, function(err, user) {
if (err) {
res.redirect("/users/");
} else {
res.redirect("/users/" + req.params.id);
}});
});