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

Push to gh #63

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ web_modules
node_modules
.DS_Store
tailwind.output.css
.env
.env.*
# .env
# .env.*
23,101 changes: 22,731 additions & 370 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 13 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "rigflo",
"main": "public/electron.js",
"browserslist": [
"since 2017-06"
],
"scripts": {
"dev": "run-p dev:**",
"dev:snowpack": "snowpack dev",
"dev:reload": "snowpack --reload",
"start": "npm-run-all --parallel watch:tailwind dev:snowpack",
"dev:server": "NODE_ENV=development nodemon ./server/server.js",
"start": "npm-run-all --parallel watch:tailwind dev:snowpack dev:server",
"build": "snowpack build",
"build:tailwind": "tailwind build src/tailwind.css -o src/tailwind.output.css",
"watch:tailwind": "chokidar 'src/**/*.css' 'src/**/*.scss' --ignore src/tailwind.output.css -c 'npm run build:tailwind'",
Expand All @@ -20,35 +20,41 @@
"@fortawesome/free-brands-svg-icons": "5.15.1",
"@fortawesome/react-fontawesome": "0.1.12",
"@headlessui/react": "0.2.0",
"@octokit/core": "3.2.1",
"@reach/router": "1.3.4",
"@tailwindcss/ui": "0.6.2",
"ajv": "^6.12.6",
"axios": "0.21.0",
"body-parser": "1.19.0",
"chokidar-cli": "2.1.0",
"cors": "2.8.5",
"electron": "10.1.4",
"electron-is-dev": "1.2.0",
"express": "4.17.1",
"heroicons-react": "1.3.0",
"mobx-react-lite": "^3.0.1",
"mongoose": "5.10.13",
"npm-run-all": "4.1.5",
"react": "^16.13.1",
"react-async-hook": "3.6.2",
"react-dom": "^16.13.1",
"react-flow-renderer": "6.1.3",
"react-json-pretty": "^2.2.0",
"react-modal": "^3.11.2",
"snowpack": "^2.15.0",
"tailwindcss": "1.9.5",
"wait-on": "5.2.0",
"snowpack": "^2.15.0"
"wait-on": "5.2.0"
},
"devDependencies": {
"@babel/cli": "7.12.1",
"@babel/core": "7.12.3",
"@babel/plugin-syntax-jsx": "*",
"@babel/preset-react": "^7.12.1",
"@snowpack/app-scripts-react": "^1.12.4",
"@snowpack/plugin-babel": "*",
"@snowpack/plugin-dotenv": "^2.0.4",
"@snowpack/plugin-react-refresh": "^2.3.4",
"@snowpack/plugin-webpack": "2.1.1",
"@snowpack/plugin-babel": "*",
"@babel/plugin-syntax-jsx": "*",
"@snowpack/web-test-runner-plugin": "^0.1.3",
"@testing-library/react": "^11.0.0",
"@web/test-runner": "^0.9.0",
Expand Down
Binary file removed public/favicon.ico
Binary file not shown.
4 changes: 2 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta
name="description"
content="Web site created using create-snowpack-app"
content="A design first approach to speed up API delivery"
/>
<title>rigflo</title>
<title>rigflo | API Visualization & Design</title>
</head>
<body>
<div id="root"></div>
Expand Down
4 changes: 4 additions & 0 deletions server/.env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MONGO_URI="mongodb://localhost:27017/?connectTimeoutMS=10000"
GITHUB_CLIENT_SECRET="d448899a40b1ec8a954e72344abae29880cec485"
GITHUB_CLIENT_ID="9736e547efbf758aa0dc"
BASE_URL=
4 changes: 4 additions & 0 deletions server/.env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MONGO_URI="mongodb+srv://rigflo-admin:[email protected]/rigflo?retryWrites=true&w=majority"
GITHUB_CLIENT_SECRET="d448899a40b1ec8a954e72344abae29880cec485"
GITHUB_CLIENT_ID="9736e547efbf758aa0dc"
BASE_URL=
30 changes: 30 additions & 0 deletions server/controllers/projectController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const Project = require('../models/projectModel');

const projectController = {};

projectController.saveProject = async (req, res, next) => {
try {
console.log('BODY:', req.body);
console.log(req.headers);
const { project } = req.body;

console.log({ project });

// Create a new project
const createdProject = await Project.create({ project });

console.log({ createdProject });

res.locals.project = createdProject._id;
return next();
} catch (e) {
return next({
log: `Error caught in projectController.saveProject. \n Error Message: ${
e.errmsg || e
}`,
message: { err: e.errmsg || e },
});
}
};

module.exports = projectController;
51 changes: 51 additions & 0 deletions server/controllers/repoController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const axios = require('axios');

const repoController = {};

repoController.createNewRepo = async (req, res, next) => {
const { token } = req.query;
const { elements } = req.body;

console.log({ token });

const body = JSON.stringify({ name: `rigflo - ${Date.now()}` });

try {
const config = {
url: 'user/repos',
method: 'post',
baseURL: 'https://api.github.com/',
headers: {
Authorization: `token ${token}`,
'Content-Type': 'application/json',
},
data: body,
responseType: 'json',
};

const { data } = await axios(config)
.then((response) => {
console.log(response.data);
console.log(response.status);
console.log(response.statusText);
console.log(response.headers);
console.log(response.config);
return response;
})
.catch((error) => console.log({ error }));

console.log({ data });
res.locals.data = data;
console.log('after setting locals');
return next();
} catch (e) {
return next({
log: `Error caught in repoController.createNewRepo. \n Error Message: ${
e.errmsg || e
}`,
message: { err: e.errmsg || e },
});
}
};

module.exports = repoController;
87 changes: 87 additions & 0 deletions server/controllers/userController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const axios = require('axios');

// const User = require('../models/userModel');

const userController = {};

// Get the auth code from Github
userController.authenticateUser = async (req, res, next) => {
const randomString = '9323bb9ce6934469b58303863f8c0d54';

try {
const { code, state } = req.query;

// VERIFY REQUEST FOR OAUTH SECURITY.
if (!state === randomString) {
return res.status(401).send('Unauthorized request');
}

// SAVE TEMPORARY AUTH CODE
res.locals.authCode = code;

return next();
} catch (e) {
return next({
log: `Error caught in userController.authenticateUser. \n Error Message: ${
e.errmsg || e
}`,
message: { err: e.errmsg || e },
});
}
};

// Get access token from Github
userController.requestToken = async (req, res, next) => {
const clientID = process.env.GITHUB_CLIENT_ID;
const clientSecret = process.env.GITHUB_CLIENT_SECRET;
const { authCode } = res.locals;

try {
axios({
method: 'post',
url: `https://github.com/login/oauth/access_token?client_id=${clientID}&client_secret=${clientSecret}&code=${authCode}&scope=repos`,
headers: {
accept: 'application/json',
},
}).then((response) => {
res.locals.access_token = response.data.access_token;
return next();
});
} catch (e) {
return next({
log: `Error caught in userController.requestToken. \n Error Message: ${
e.errmsg || e
}`,
message: { err: e.errmsg || e },
});
}
};

// Get the user profile from Github
userController.getUserProfile = async (req, res, next) => {
try {
const config = {
method: 'get',
url: 'https://api.github.com/user',
headers: {
Accept: 'application/vnd.github.v3+json',
Authorization: `token ${res.locals.access_token}`,
},
};

const { data } = await axios(config);

res.locals.user = data;

return next();
} catch (e) {
return next({
log: `Error caught in userController.getUserProfile. \n Error Message: ${
e.errmsg || e
}`,
message: { err: e.errmsg || e },
});
}
};

module.exports = userController;
File renamed without changes.
9 changes: 9 additions & 0 deletions server/models/projectModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const mongoose = require('mongoose');
const { Schema } = mongoose;

const projectSchema = new Schema({
project: Object,
_created_at: { type: Date, default: Date.now },
});

module.exports = mongoose.model('project', projectSchema);
21 changes: 21 additions & 0 deletions server/models/userModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const mongoose = require('mongoose');
const { Schema } = mongoose;

// sets a schema for 'users'
const userSchema = new Schema({
login: String,
id: { type: Number, unique: true, required: true },
avatar_url: String,
url: String,
html_url: String,
name: String,
email: String,
public_repos: String,
access_token: String,
_created_at: { type: Date, default: Date.now },
full_object: Object,
configurations: [{ type: Schema.Types.ObjectId, ref: 'configs' }],
});

// exports all the models in an object to be used in the controller
module.exports = mongoose.model('user', userSchema);
44 changes: 44 additions & 0 deletions server/routes/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const express = require('express');
const cors = require('cors');

const router = express.Router();

const userController = require('../controllers/userController');
const projectController = require('../controllers/projectController');
const repoController = require('../controllers/repoController');

// router.use(cors());

router.get(
'/login/callback',
userController.authenticateUser,
userController.requestToken,
userController.getUserProfile,
(req, res) => {
const { login, avatar_url } = res.locals.user;
res.redirect(
`http://localhost:8080/login/callback?access_token=${res.locals.access_token}&login=${login}&avatar_url=${avatar_url}`,
);
},
);

router.post('/projects', projectController.saveProject, (req, res) => {
console.log('sending back status');
return res.send('yep');
});

router.post('/repos', cors(), repoController.createNewRepo, (req, res) => {
console.log('final callback');
const { id, name, html_url } = res.locals.data;
console.log({ id });
console.log({ name });
console.log({ html_url });
const response = {
id,
name,
html_url,
};
res.status(201).json(response);
});

module.exports = router;
Loading