Skip to content
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
91 changes: 91 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
See http://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist
/tmp
/out-tsc

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# IDEs and editors
.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# misc
.sass-cache
connect.lock
typings

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*


# Dependency directories
node_modules/
jspm_packages/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next

# Lerna
lerna-debug.log

# System Files
.DS_Store
Thumbs.db
3 changes: 3 additions & 0 deletions config/keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
mongoURI: "mongodb://at:[email protected]:57732/uiuxcodechallenge"
};
58 changes: 58 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const express = require("express");
const bodyParser = require("body-parser");
const OktaJwtVerifier = require("@okta/jwt-verifier");

const oktaJwtVerifier = new OktaJwtVerifier({
issuer: "https://dev-982217.oktapreview.com/oauth2/default"
});

const authenticationRequired = (req, res, next) => {
if (!req.headers.authorization) {
return next(new Error("Authorization header is required"));
}
let parts = req.headers.authorization.trim().split(" ");
let accessToken = parts.pop();
oktaJwtVerifier
.verifyAccessToken(accessToken)
.then(jwt => {
req.user = {
uid: jwt.claims.uid,
email: jwt.claims.sub
};
next();
})
.catch(err => {
res.status(401).send(err.message);
});
};

const app = express();
app.use(bodyParser.json());
app.use(express.static("public"));

// store in memory
let meals = [];

app.get("/meals", authenticationRequired, (req, res) => {
return res.send(meals);
});

app.post("/meals", authenticationRequired, (req, res) => {
let meal = req.body;
meal.id = Date.now();
meals.push(meal);
return res.send(meal);
});

app.delete("/meals/:id", authenticationRequired, (req, res) => {
let id = parseInt(req.params.id);
const index = meals.map(o => o.id).indexOf(id);
if (index !== -1) {
meals.splice(index, 1);
}
return res.send();
});

app.listen(8080, () => {
console.log("App listening on port 8080!");
});
Loading