This commit is contained in:
Tben 2022-06-20 06:09:28 +01:00
parent d30036e11b
commit da6e770d7a
6 changed files with 610 additions and 55 deletions

View File

@ -5,24 +5,6 @@
"url": "https://dev.showmerebates.com/",
"image": "/images/showmerebates.jpg"
},
{
"title": "Guaranteed software",
"description": "software development agency",
"url": "https://guaranteed.software/",
"image": "/images/guaranteed.jpg"
},
{
"title": "Renition",
"description": "Curated top quality Apparel",
"url": "https://renition.com",
"image": "/images/renition-graphic.jpg"
},
{
"title": "Castcord",
"description": "Social Media web app",
"url": "https://cast-cord.com",
"image": "/images/castcord-graphic.jpg"
},
{
"title": "Next 7 Web Engine",
"description": "Next 7 is an all-in-one web engine featuring a web page builder and a content management system",

View File

@ -0,0 +1,32 @@
[
{
"title": "Showme Rebates",
"description": "Property rebates in Utah",
"url": "https://dev.showmerebates.com/",
"image": "/images/showmerebates.jpg"
},
{
"title": "Guaranteed software",
"description": "software development agency",
"url": "https://guaranteed.software/",
"image": "/images/guaranteed.jpg"
},
{
"title": "Renition",
"description": "Curated top quality Apparel",
"url": "https://renition.com",
"image": "/images/renition-graphic.jpg"
},
{
"title": "Castcord",
"description": "Social Media web app",
"url": "https://cast-cord.com",
"image": "/images/castcord-graphic.jpg"
},
{
"title": "Next 7 Web Engine",
"description": "Next 7 is an all-in-one web engine featuring a web page builder and a content management system",
"url": "https://next7.io",
"image": "/images/next-7-graphic-min.jpg"
}
]

View File

@ -0,0 +1,135 @@
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
const http = require("http");
const https = require("https");
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/**
* ==============================================================================
* Main Function
* ==============================================================================
* @param {Object} mailObject - foundUser if any
*/
/** ********************* Main API Handler */
module.exports = async function httpFetch({ protocol, options, paradigm }) {
if (!protocol) protocol = "http";
/**
* Http(s) Response function
*
* @description handle http and https protocols differently
* @param {object} response => response object
* @param {Function} resolve => promise resolve method
* @param {Function} reject => promise reject method
*/
function httpResponse(response, resolve, reject) {
var str = "";
/** * Append data chunks to "str" variable
*/
response.on("data", function (chunk) {
str += chunk;
});
/** * the whole response has been received, so we just print it out here
*/
response.on("end", function () {
resolve(JSON.parse(str));
});
/** * Handle errors
*/
response.on("error", (err) => {
console.log(err);
reject("Fetch Failed");
});
}
/**
* Switch protocols
*
* @description handle http and https protocols differently
*/
switch (protocol) {
case "http":
/**
* Handle http protocol
*
* @description handles fetch requests with http protocol
* @see => handles strapi api calls only for now
*/
return await new Promise((resolve, reject) => {
http.request(
/** * Make Request
* @abstract Make Request
*/
{
...options,
host: "localhost",
port: "1337",
// path: "/api/blog-posts",
// href: "http://localhost:1337/api/blog-posts",
headers: {
Authorization: `bearer ${process.env.STRAPI_API_KEY_DEV}`,
},
},
/** * Handle Response
* @abstract Handle response
*/
(response) => {
httpResponse(response, resolve, reject);
}
).end();
});
break;
case "https":
/**
* Handle http protocol
*
* @description handles fetch requests with http protocol
* @see => handles strapi api calls only for now
*/
return await new Promise((resolve, reject) => {
https.request(
/** * Make Request
* @abstract Make Request
*/
{
...options,
host: "cms.showmerebates.com",
headers: {
Authorization: `bearer ${process.env.STRAPI_API_KEY}`,
},
},
/** * Handle Response
* @abstract Handle response
*/
(response) => {
httpResponse(response, resolve, reject);
}
).end();
});
break;
default:
break;
}
};
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */

396
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -26,6 +26,7 @@
"homepage": "https://github.com/BenjaminToby/personal_site#readme",
"dependencies": {
"@barba/core": "^2.9.7",
"contentful": "^9.1.32",
"gsap": "^3.10.4",
"next": "^12.0.4",
"nodemailer": "^6.7.2",

View File

@ -5,7 +5,9 @@
*/
import React from "react";
import Head from "next/head";
const fs = require("fs");
const contentful = require('contentful');
/** ********************************************** */
/** ********************************************** */
@ -13,6 +15,7 @@ const fs = require("fs");
import GeneralLayout from "../../layouts/general_layout/GeneralLayout";
import TextShuffler from "../../components/actions/TextShuffler";
import httpFetch from "../../functions/backend/httpFetch";
/** ****************************************************************************** */
/** ****************************************************************************** */
@ -28,31 +31,35 @@ import TextShuffler from "../../components/actions/TextShuffler";
* @param {Object} props - Server props
*/
export default function BlogIndex(props) {
// ## Get Contexts
/**
* Get Contexts
*
* @abstract { React.useContext }
*/
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
// ## Javascript Variables
// const blogPosts = require("../../jsonData/blogposts.json");
/**
* Javascript Variables
*
* @abstract Non hook variables and functions
*/
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
/**
* React Hooks
*
* @abstract { useState, useEffect, useRef, etc ... }
*/
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
// ## React Hooks { useState, useEffect, useRef, etc ... }
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
// ## Function Return
/**
* Function Return
*
* @abstract Main Function Return
*/
return (
<React.Fragment>
<Head>
@ -77,8 +84,7 @@ export default function BlogIndex(props) {
</GeneralLayout>
</React.Fragment>
);
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
};
@ -97,22 +103,37 @@ export default function BlogIndex(props) {
* @param {Object} res - http response object
* @param {Object} query - queries attached to the url
*/
export async function getServerSideProps({ req, res, query }) {
// ## Environment processes
export async function getStaticProps({ req, res, query }) {
/**
* User Auth
*
* @abstract grab user
*/
// const contentfulClient = contentful.createClient({
// space: process.env.CONTENTFUL_SPACE_ID,
// accessToken: process.env.CONTENTFUL_API_KEY,
// });
// const posts = await contentfulClient.getEntries()
// console.log(posts);
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
// ## User Authentication
/**
* Data fetching
*
* @abstract fetch date from the server or externnal source
*/
// let blogPosts = await httpFetch({
// options: {
// method:"DELETE",
// path: "/api/tben-blogs"
// },
// paradigm:"https"
// })
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
// ## Page/Site Data Data Fetching
const blogPosts = fs.readFileSync("./jsonData/blogposts.json", "utf8");
// console.log(blogPosts.data);
/** ********************************************** */
/** ********************************************** */
@ -121,7 +142,7 @@ export async function getServerSideProps({ req, res, query }) {
// ## Server Props Return
return {
props: {
blogPosts: JSON.parse(blogPosts).reverse(),
blogPosts: [],
},
};