-
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
Aaron Arney
committed
Jan 14, 2019
0 parents
commit bc55eaa
Showing
136 changed files
with
17,045 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# /node_modules/* and /bower_components/* ignored by default | ||
|
||
docs/* | ||
coverage/* |
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,22 @@ | ||
{ | ||
"extends": [ | ||
"plugin:security/recommended", | ||
"airbnb" | ||
], | ||
"plugins": [ | ||
"mocha", | ||
"security" | ||
], | ||
"env": { | ||
"node": true, | ||
"mocha": true | ||
}, | ||
"rules": { | ||
"quotes": ["error", "single"], | ||
"indent": ["error", 4, { "SwitchCase": 1 }], | ||
"no-unused-expressions": "off", | ||
"no-underscore-dangle": "off", | ||
"quote-props": "off", | ||
"padded-blocks": "off" | ||
} | ||
} |
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,5 @@ | ||
node_modules/ | ||
.nyc_output/ | ||
coverage/ | ||
.idea/ | ||
.DS_Store |
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 @@ | ||
{} |
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,20 @@ | ||
# Changelog | ||
|
||
## 0.8.1 | ||
- Fix the way tokens were being attached to User models | ||
|
||
## 0.7.3 | ||
- Add additional tests | ||
|
||
## 0.7.2 | ||
- Add eslint and correct existing lint errors | ||
- Add node-security eslint plugin | ||
- Refactor error handler | ||
- Update tests to reflect new error structure | ||
|
||
## 0.7.1 | ||
|
||
- Update API docs | ||
- Allow spaces in the client field when registering a new user | ||
- Allow underscores in the username field when registering a new user | ||
- Update user tests to reflect new username and client field policies |
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,65 @@ | ||
# "Clue" Server | ||
|
||
This node server is part of the larger "Clue" app, which is an event logger for WordPress. I believe that this server is partially incomplete, but should be functional in its current state. | ||
|
||
As of writing this, I have not touched the code in this app in over a year so I am somewhat fuzzy on some of the details. However, I built this wholly aware that I wanted to "set and forget," so should be easy to reason about if given a little time to read through the code. | ||
|
||
The tools used for this app are: | ||
- Node v9.10.1 | ||
- Express | ||
- MongoDB with Mongoose | ||
- Mocha/Chai for testing with NYC for coverage reporting | ||
- eslint for quality | ||
|
||
|
||
## Getting Started | ||
|
||
Clone the repository and install dependencies: | ||
```bash | ||
yarn install | ||
``` | ||
|
||
Install LocalTunnel in order to expose your local environment to the web: | ||
```bash | ||
yarn add localtunnel -G | ||
``` | ||
|
||
Next, boot up mongodb and run the server: | ||
```bash | ||
mongod | ||
yarn start | ||
``` | ||
|
||
Lastly start localtunnel with a subdomain of "clue" (to make things easier) and port of `3000`: | ||
```bash | ||
lt -S "clue" -p 3000 | ||
``` | ||
|
||
Test everything works by sending a request for all events: | ||
```bash | ||
curl https://clue.localtunnel.me/api/v1/event | ||
``` | ||
|
||
You should have received: | ||
```json | ||
{"status":401,"message":""} | ||
``` | ||
|
||
|
||
## API Documentation | ||
|
||
The documentation is generated using the `api-doc-generator` package. [The output](./docs/index.html) for this is put into the `docs` directory. | ||
|
||
|
||
## Testing | ||
|
||
The test harness utilized for unit tests is `mocha` and `chai`. Code coverage is generated using `nyc`. | ||
|
||
You will need to have an instance of `mongo` running, prior to invoking the tests. | ||
|
||
To run the tests: | ||
```bash | ||
sudo mongod | ||
yarn test | ||
``` | ||
|
Empty file.
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,7 @@ | ||
{ | ||
"name": "Clue API", | ||
"version": "0.7.3", | ||
"description": "Clue API docs", | ||
"title": "Clue API", | ||
"url" : "https://secure-peak-56909.herokuapp.com/api/v1" | ||
} |
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,58 @@ | ||
const express = require('express'); | ||
const winston = require('winston'); | ||
const compression = require('compression'); | ||
const cookieParser = require('cookie-parser'); | ||
const bodyParser = require('body-parser'); | ||
const helmet = require('helmet'); | ||
const mongoSanitize = require('express-mongo-sanitize'); | ||
const mongoose = require('./db/mongoose'); | ||
|
||
const app = express(); | ||
const logger = winston.createLogger({ | ||
transports: [ | ||
new winston.transports.Console(), | ||
new winston.transports.File({ filename: 'combined.log' }), | ||
] | ||
}); | ||
|
||
app.use(bodyParser.json({ | ||
type: "*/*", | ||
})); | ||
app.use(bodyParser.urlencoded({ extended: true })); | ||
app.use(cookieParser()); | ||
app.use(helmet()); | ||
app.use(mongoSanitize()); | ||
app.use(compression()); | ||
|
||
app.all('/*', function (req, res, next) { | ||
res.header('Access-Control-Allow-Origin', '*'); | ||
res.header('Access-Control-Allow-Methods', 'GET,POST'); | ||
res.header('Access-Control-Allow-Headers', 'Content-type,Accept,X-Access-Token,X-Key,X-auth'); | ||
next(); | ||
}); | ||
|
||
|
||
// Define routes | ||
// These MUST come after all app configurations or else they get fucked up. | ||
// Reference: https://stackoverflow.com/questions/9177049/express-js-req-body-undefined | ||
require('./components/event/eventRoutes.js')(app); | ||
require('./components/user/userRoutes.js')(app); | ||
|
||
|
||
// Error handler middleware | ||
app.use((err, req, res, next) => { | ||
|
||
logger.error(err); | ||
|
||
if (!err.isOperational) { | ||
// This is a programmer error and we need to do something special with it | ||
// probably send an email and a slack notification. | ||
} | ||
|
||
res.status(err.status).json({ | ||
status: err.status, | ||
message: err.message, | ||
}); | ||
}); | ||
|
||
module.exports = app; |
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,59 @@ | ||
#!/usr/bin/env node | ||
const app = require('../app'); | ||
const debug = require('debug')('wp-history-server:server'); | ||
const http = require('http'); | ||
|
||
function normalizePort(val) { | ||
const port = parseInt(val, 10); | ||
|
||
if (Number.isNaN(port)) { | ||
return val; | ||
} | ||
|
||
if (port >= 0) { | ||
return port; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
const port = normalizePort(process.env.PORT || '3000'); | ||
const server = http.createServer(app); | ||
|
||
function onError(error) { | ||
if (error.syscall !== 'listen') { | ||
throw error; | ||
} | ||
|
||
const bind = typeof port === 'string' ? `Pipe ${port}` : `Port ${port}`; | ||
|
||
// handle specific listen errors with friendly messages | ||
switch (error.code) { | ||
case 'EACCES': | ||
debug(`${bind} requires elevated privileges`); | ||
process.exit(1); | ||
break; | ||
|
||
case 'EADDRINUSE': | ||
debug(`${bind} is already in use`); | ||
process.exit(1); | ||
break; | ||
|
||
default: | ||
throw error; | ||
} | ||
} | ||
|
||
|
||
function onListening() { | ||
const addr = server.address(); | ||
const bind = typeof addr === 'string' ? `pipe ${addr}` : `port ${addr.port}`; | ||
debug(`Listening on ${bind}`); | ||
} | ||
|
||
app.set('port', port); | ||
server.listen(port); | ||
server.on('error', onError); | ||
server.on('listening', onListening); | ||
|
||
module.exports = server; |
Oops, something went wrong.