Initial import
This commit is contained in:
1 parent
9540be8162
commit
8274b67bda
14 files changed
+7145
No files matched your search
@@ -0,0 +1,9 @@
|
||||
module.exports = {
|
||||
parser: 'babel-eslint',
|
||||
extends: 'airbnb-base',
|
||||
rules: {
|
||||
'max-len': ['error', 140, 2],
|
||||
'no-underscore-dangle': 'off',
|
||||
'no-param-reassign': 'off',
|
||||
}
|
||||
};
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
|
||||
# Build folder js files
|
||||
build/
|
||||
dist/
|
||||
|
||||
# Visual Studio Code
|
||||
.vscode
|
||||
|
||||
#Mac specific files
|
||||
.DS_Store
|
||||
Generated
+6923
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "logs-server",
|
||||
"version": "0.0.1",
|
||||
"description": "Superalgos Logs backend API",
|
||||
"author": "",
|
||||
"license": "",
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
"start": "nodemon --exec babel-node --presets env,stage-2 src/index.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"standard": {
|
||||
"ignore": [
|
||||
"/src/errors/index.js"
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.26.0",
|
||||
"babel-eslint": "^10.0.1",
|
||||
"babel-preset-env": "^1.7.0",
|
||||
"babel-preset-stage-2": "^6.24.1",
|
||||
"eslint": "^5.8.0",
|
||||
"eslint-config-airbnb-base": "^13.1.0",
|
||||
"eslint-plugin-import": "^2.14.0",
|
||||
"nodemon": "^1.18.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"apollo-server-express": "^2.1.0",
|
||||
"axios": "^0.18.0",
|
||||
"dotenv": "^6.0.0",
|
||||
"express": "^4.16.3",
|
||||
"graphql": "^0.13.2",
|
||||
"mongoose": "^5.3.4"
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
import 'dotenv/config';
|
||||
import express from 'express';
|
||||
import { ApolloServer } from 'apollo-server-express';
|
||||
import schema from './schema';
|
||||
import wrongPreshared from './errors/notAllowed.json';
|
||||
|
||||
const app = express();
|
||||
|
||||
app.post('/graphql', (req, res, next) => {
|
||||
if (req.headers.preshared === process.env.PRESHARED_GATEWAY_KEY) {
|
||||
next();
|
||||
} else {
|
||||
res.send(wrongPreshared);
|
||||
}
|
||||
});
|
||||
|
||||
// Starting the graphql server
|
||||
const server = new ApolloServer({
|
||||
schema,
|
||||
playground: {
|
||||
settings: {
|
||||
'editor.theme': 'dark',
|
||||
'editor.cursorShape': 'line',
|
||||
},
|
||||
},
|
||||
context: ({ req }) => ({
|
||||
userId: req.headers.userid,
|
||||
authorization: req.headers.authorization,
|
||||
}),
|
||||
formatError: error => ({
|
||||
code: error.extensions.exception.code,
|
||||
message: error.message,
|
||||
path: error.path,
|
||||
}),
|
||||
introspection: true,
|
||||
});
|
||||
|
||||
server.applyMiddleware({
|
||||
app,
|
||||
cors: true,
|
||||
});
|
||||
|
||||
export default app;
|
||||
@@ -0,0 +1,21 @@
|
||||
class ClientError extends Error {
|
||||
}
|
||||
|
||||
|
||||
export class AuthentificationError extends ClientError {
|
||||
code = 401
|
||||
|
||||
message = 'Autentification not found, you have to be authentificated to perform this action'
|
||||
}
|
||||
|
||||
export class DatabaseError extends ClientError {
|
||||
code = 404
|
||||
|
||||
message = `Ressource not found : ${this.message}`
|
||||
}
|
||||
|
||||
export class WrongArgumentsError extends ClientError {
|
||||
code = 400
|
||||
|
||||
message = `Wrong arguments : ${this.message}`
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"errors": [
|
||||
{
|
||||
"code": 401,
|
||||
"message": "Wait, you're not supposed to be here, go through the gate as everyone else"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import app from './app';
|
||||
|
||||
app.listen(process.env.PORT, () => {
|
||||
console.log(`Listening on port ${process.env.PORT}`);
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
import {
|
||||
GraphQLSchema,
|
||||
} from 'graphql';
|
||||
|
||||
import RootQuery from './queries';
|
||||
|
||||
const Schema = new GraphQLSchema({
|
||||
query: RootQuery,
|
||||
});
|
||||
|
||||
export default Schema;
|
||||
@@ -0,0 +1,28 @@
|
||||
import 'dotenv/config';
|
||||
import {
|
||||
GraphQLID,
|
||||
GraphQLSchema,
|
||||
GraphQLString
|
||||
} from 'graphql';
|
||||
|
||||
import { LogLinkIDType } from '../types';
|
||||
|
||||
const crypto = require('crypto');
|
||||
|
||||
|
||||
const query = {
|
||||
loglinkid: {
|
||||
type: LogLinkIDType,
|
||||
args: { seedID: { type: GraphQLID } },
|
||||
resolve(parent, args){
|
||||
// code to get data from db / other source
|
||||
const hash = crypto.createHash('sha256');
|
||||
hash.update(process.env.PRESHARED_ELK_LOG_KEY+args.seedID);
|
||||
|
||||
return { value: process.env.BEGIN_URL_ELK_LOG+hash.digest('hex')+process.env.END_URL_ELK_LOG };
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export default query;
|
||||
@@ -0,0 +1,14 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
} from 'graphql';
|
||||
|
||||
import CalcLogLinkIDQuery from './CalcLogLinkID';
|
||||
|
||||
const RootQuery = new GraphQLObjectType({
|
||||
name: 'RootQueryType',
|
||||
fields: Object.assign(
|
||||
CalcLogLinkIDQuery,
|
||||
),
|
||||
});
|
||||
|
||||
export default RootQuery;
|
||||
@@ -0,0 +1,17 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLString,
|
||||
GraphQLID
|
||||
} from 'graphql';
|
||||
|
||||
|
||||
const LogLinkIDType = new GraphQLObjectType({
|
||||
name: 'LogLinkID',
|
||||
description: 'Generate de LogLinkID',
|
||||
fields: () => ({
|
||||
seedID: { type: GraphQLID },
|
||||
value: { type: GraphQLString },
|
||||
}),
|
||||
});
|
||||
|
||||
export default LogLinkIDType;
|
||||
@@ -0,0 +1,5 @@
|
||||
import LogLinkIDType from './LogLinkID';
|
||||
|
||||
export {
|
||||
LogLinkIDType,
|
||||
};
|
||||
Reference in new issue
Block a user