Skip to content

Commit

Permalink
Merge 440879e into cfb7be1
Browse files Browse the repository at this point in the history
  • Loading branch information
fire-cracker committed Feb 5, 2019
2 parents cfb7be1 + 440879e commit dbeef4d
Show file tree
Hide file tree
Showing 39 changed files with 9,933 additions and 1,103 deletions.
11 changes: 11 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"presets": [
[
"@babel/preset-env", {
"targets": {
"node": "current"
}
}
]
]
}
33 changes: 33 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"root": true,
"extends": "airbnb-base",
"env": {
"node": true,
"es6": true,
"mocha": true
},
"rules": {
"one-var": 0,
"one-var-declaration-per-line": 0,
"new-cap": 0,
"consistent-return": 0,
"no-param-reassign": 0,
"comma-dangle": 0,
"curly": ["error", "multi-line"],
"import/no-unresolved": [2, { "commonjs": true }],
"no-shadow": ["error", { "allow": ["req", "res", "err"] }],
"valid-jsdoc": ["error", {
"requireReturn": true,
"requireReturnType": true,
"requireParamDescription": false,
"requireReturnDescription": true
}],
"require-jsdoc": ["error", {
"require": {
"FunctionDeclaration": true,
"MethodDefinition": true,
"ClassDeclaration": true
}
}]
}
}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ node_modules
# Optional REPL history
.node_repl_history

# Enviromental
.env

# Coveralls and Coverage folder
.coveralls.yml
.nyc_output
4 changes: 4 additions & 0 deletions .hound.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
eslint:
enabled: true
config_file: .eslintrc.json
ignore_file: .eslintignore.json
8 changes: 8 additions & 0 deletions .sequelizerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const path = require('path');

module.exports = {
"config": path.resolve('./server/config', 'config.js'),
"models-path": path.resolve('./server/models'),
"seeders-path": path.resolve('./server/seeders'),
"migrations-path": path.resolve('./server/migrations')
};
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: node_js

node_js:
- "11.6.0"

after_success: npm run coverage
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
Authors Haven - A Social platform for the creative at heart.
=======
# Authors Haven - A Social platform for the creative at heart.

[![Build Status](https://travis-ci.org/andela/denethor-ah-backend.svg?branch=master)](https://travis-ci.org/andela/denethor-ah-backend) [![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com) [![Coverage Status](https://coveralls.io/repos/github/andela/denethor-ah-backend/badge.svg?branch=master)](https://coveralls.io/github/andela/denethor-ah-backend?branch=master)

## Vision

Create a community of like minded authors to foster inspiration and innovation
by leveraging the modern web.

---

## API Spec

The preferred JSON object to be returned by the API should be structured as follows:

### Users (for authentication)
Expand All @@ -23,7 +26,9 @@ The preferred JSON object to be returned by the API should be structured as foll
}
}
```

### Profile

```source-json
{
"profile": {
Expand All @@ -34,7 +39,9 @@ The preferred JSON object to be returned by the API should be structured as foll
}
}
```

### Single Article

```source-json
{
"article": {
Expand All @@ -56,7 +63,9 @@ The preferred JSON object to be returned by the API should be structured as foll
}
}
```

### Multiple Articles

```source-json
{
"articles":[{
Expand Down Expand Up @@ -96,7 +105,9 @@ The preferred JSON object to be returned by the API should be structured as foll
"articlesCount": 2
}
```

### Single Comment

```source-json
{
"comment": {
Expand All @@ -113,7 +124,9 @@ The preferred JSON object to be returned by the API should be structured as foll
}
}
```

### Multiple Comments

```source-json
{
"comments": [{
Expand All @@ -131,7 +144,9 @@ The preferred JSON object to be returned by the API should be structured as foll
"commentsCount": 1
}
```

### List of Tags

```source-json
{
"tags": [
Expand All @@ -140,7 +155,9 @@ The preferred JSON object to be returned by the API should be structured as foll
]
}
```

### Errors and Status Codes

If a request fails any validations, expect errors in the following format:

```source-json
Expand All @@ -152,16 +169,16 @@ If a request fails any validations, expect errors in the following format:
}
}
```

### Other status codes:

401 for Unauthorized requests, when a request requires authentication but it isn't provided

403 for Forbidden requests, when a request may be valid but the user doesn't have permissions to perform the action

404 for Not found requests, when a resource can't be found to fulfill the request


Endpoints:
----------
## Endpoints:

### Authentication:

Expand Down
8 changes: 4 additions & 4 deletions config/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
secret:
process.env.NODE_ENV === "production" ? process.env.SECRET : "secret"
};
// module.exports = {
// secret:
// process.env.NODE_ENV === 'production' ? process.env.SECRET : 'secret'
// };
26 changes: 0 additions & 26 deletions config/passport.js

This file was deleted.

108 changes: 33 additions & 75 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,93 +1,51 @@
const fs = require("fs"),
http = require("http"),
path = require("path"),
methods = require("methods"),
express = require("express"),
bodyParser = require("body-parser"),
session = require("express-session"),
cors = require("cors"),
passport = require("passport"),
errorhandler = require("errorhandler"),
mongoose = require("mongoose");
import express from 'express';
import bodyParser from 'body-parser';
import session from 'express-session';
import cors from 'cors';
import dotenv from 'dotenv';
import chalk from 'chalk';
import { createLogger, format, transports } from 'winston';

const logger = createLogger({
level: 'debug',
format: format.simple(),
transports: [new transports.Console()]
});

const isProduction = process.env.NODE_ENV === "production";
dotenv.config();

const port = process.env.PORT || process.env.LOCAL_PORT;
// Create global app object
const app = express();

app.use(cors());

// Normal express config defaults
app.use(require("morgan")("dev"));
app.use(require('morgan')('dev'));

app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

app.use(require("method-override")());
app.use(express.static(__dirname + "/public"));
app.use(require('method-override')());

app.use(express.static(`${__dirname}/public`));

app.use(
session({
secret: "authorshaven",
cookie: { maxAge: 60000 },
resave: false,
saveUninitialized: false
})
session({
secret: 'authorshaven',
cookie: { maxAge: 60000 },
resave: false,
saveUninitialized: false
})
);

if (!isProduction) {
app.use(errorhandler());
}

if (isProduction) {
mongoose.connect(process.env.MONGODB_URI);
} else {
mongoose.connect("mongodb://localhost/conduit");
mongoose.set("debug", true);
}
app.get('/', (req, res) => res.status(200).send({
status: 'connection successful',
message: 'Welcome to Author Haven!',
}));

require("./models/User");

app.use(require("./routes"));

/// catch 404 and forward to error handler
app.use(function(req, res, next) {
const err = new Error("Not Found");
err.status = 404;
next(err);
app.listen(port, () => {
logger.debug(`Server running on port ${chalk.blue(port)}`);
});

/// error handlers

// development error handler
// will print stacktrace
if (!isProduction) {
app.use(function(err, req, res, next) {
console.log(err.stack);

res.status(err.status || 500);

res.json({
errors: {
message: err.message,
error: err
}
});
});
}

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.json({
errors: {
message: err.message,
error: {}
}
});
});

// finally, let's start our server...
const server = app.listen(process.env.PORT || 3000, function() {
console.log("Listening on port " + server.address().port);
});
export default app;
Loading

0 comments on commit dbeef4d

Please sign in to comment.