diff --git a/.gitignore b/.gitignore index 4d29575d..ba736b0f 100644 --- a/.gitignore +++ b/.gitignore @@ -7,12 +7,14 @@ # testing /coverage +/.history # production /build # misc .DS_Store +.env .env.local .env.development.local .env.test.local diff --git a/package-lock.json b/package-lock.json index 83ce7397..1293a7db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "name": "starter-react-app", "version": "0.1.0", "dependencies": { + "dotenv": "^16.3.1", "express": "^4.17.3" }, "devDependencies": { @@ -6490,12 +6491,14 @@ } }, "node_modules/dotenv": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz", - "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==", - "dev": true, + "version": "16.3.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.3.1.tgz", + "integrity": "sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==", "engines": { - "node": ">=10" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/motdotla/dotenv?sponsor=1" } }, "node_modules/dotenv-expand": { @@ -12743,6 +12746,15 @@ } } }, + "node_modules/react-scripts/node_modules/dotenv": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz", + "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==", + "dev": true, + "engines": { + "node": ">=10" + } + }, "node_modules/readable-stream": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", @@ -20447,10 +20459,9 @@ } }, "dotenv": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz", - "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==", - "dev": true + "version": "16.3.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.3.1.tgz", + "integrity": "sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==" }, "dotenv-expand": { "version": "5.1.0", @@ -24980,6 +24991,14 @@ "webpack-dev-server": "^4.6.0", "webpack-manifest-plugin": "^4.0.2", "workbox-webpack-plugin": "^6.4.1" + }, + "dependencies": { + "dotenv": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz", + "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==", + "dev": true + } } }, "readable-stream": { diff --git a/package.json b/package.json index faa0ee1c..eaee36bf 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ ] }, "dependencies": { + "dotenv": "^16.3.1", "express": "^4.17.3" }, "devDependencies": { diff --git a/server.js b/server.js index d250b0c0..cf41b85e 100644 --- a/server.js +++ b/server.js @@ -2,7 +2,9 @@ const express = require('express') const path = require("path"); const app = express() +require('dotenv').config() +let bearerToken = process.env.OPEN_AI_KEY; // ############################################################################# // This configures static hosting for files in /public that have the extensions // listed in the array. @@ -18,6 +20,31 @@ app.use(express.static('build', options)) const port = process.env.PORT || 3000 +app.post("/generateBlog", async (req, response)=>{ + console.log(req.body) + + await fetch("https://api.openai.com/v1/chat/completions", { + method: "POST", + mode: "cors", + cache: "no-cache", + credentials: "same-origin", + headers: { + "Authorization" : "Bearer " + bearerToken, + "Content-Type": "application/json" + }, + body: JSON.stringify({ + "model": "gpt-3.5-turbo", + "messages": [{"role": "user", "content": "Say whadup doc!"}], + "temperature": 0.7 + }) + }).then(res=>{ + console.log(res.body) + response.send(res.body) + }).catch((err)=>{ + response.send("error") + }) +}); + app.listen(port, () => { console.log(`React app listening at http://localhost:${port}`) }) diff --git a/src/App.js b/src/App.js index 37845757..8f572f12 100644 --- a/src/App.js +++ b/src/App.js @@ -2,24 +2,43 @@ import logo from './logo.svg'; import './App.css'; function App() { - return ( -
- Edit src/App.js
and save to reload.
-