From 8e9fd6433dd98c686ef790673a0a2cc53aae1776 Mon Sep 17 00:00:00 2001 From: Mikayla Dobson Date: Mon, 30 May 2022 14:11:13 -0500 Subject: [PATCH] express config --- .gitignore | 5 ++++- client/src/App.tsx | 5 ++--- client/src/store/store.ts | 12 ++++++------ config.env | 2 -- package-lock.json | 14 ++++++++++++++ package.json | 1 + server.js | 14 +++++++++----- 7 files changed, 36 insertions(+), 17 deletions(-) delete mode 100644 config.env diff --git a/.gitignore b/.gitignore index 12ac647..491788d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ node_modules/ -.DS_Store \ No newline at end of file +.DS_Store + +.env +config.env \ No newline at end of file diff --git a/client/src/App.tsx b/client/src/App.tsx index 12af9fc..4be7ff4 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -1,6 +1,6 @@ import { BrowserRouter, Routes, Route } from 'react-router-dom'; -import { useContext, useReducer } from 'react'; -import { appState, initialState, reducer, AppContext } from './store/store'; +import { useContext } from 'react'; +import { AppContext } from './store/store'; import NavBar from './components/Navbar'; import LandingPage from './components/LandingPage'; @@ -11,7 +11,6 @@ import Register from './components/User/Register'; import './App.scss' function App() { - const [state, dispatch] = useReducer(reducer, initialState); const context = useContext(AppContext); return ( diff --git a/client/src/store/store.ts b/client/src/store/store.ts index e955b5a..1f40c8b 100644 --- a/client/src/store/store.ts +++ b/client/src/store/store.ts @@ -3,11 +3,11 @@ import { userInfo, Cart, } from "../types/main"; // type definitions for reducer export enum ActionType { - GETALL = 'GETALL', - GETONE = 'GETONE', - REGISTERNEW = 'REGISTERNEW', - UPDATEONE = 'UPDATEONE', - SEARCH = 'SEARCH', + GETALL, + GETCATEGORY, + REGISTERNEW, + UPDATEONE, + SEARCH, } export interface userAction { @@ -46,7 +46,7 @@ export const reducer = (state: appState, action: userAction) => { switch (type) { case ActionType.GETALL: return state; - case ActionType.GETONE: + case ActionType.GETCATEGORY: return state; case ActionType.REGISTERNEW: return state; diff --git a/config.env b/config.env deleted file mode 100644 index 0f7597a..0000000 --- a/config.env +++ /dev/null @@ -1,2 +0,0 @@ -PORT=8088 -CONNECTION=postgres://mikayladobson@localhost/ecommerce_041822 \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 32d9b0a..68de2ff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "cors": "^2.8.5", "dotenv": "^16.0.0", "express": "^4.17.3", + "helmet": "^5.1.0", "oauth2-server": "^3.1.1", "passport": "^0.6.0", "passport-local": "^1.0.0", @@ -651,6 +652,14 @@ "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=" }, + "node_modules/helmet": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/helmet/-/helmet-5.1.0.tgz", + "integrity": "sha512-klsunXs8rgNSZoaUrNeuCiWUxyc+wzucnEnFejUg3/A+CaF589k9qepLZZ1Jehnzig7YbD4hEuscGXuBY3fq+g==", + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/http-errors": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", @@ -2071,6 +2080,11 @@ "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=" }, + "helmet": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/helmet/-/helmet-5.1.0.tgz", + "integrity": "sha512-klsunXs8rgNSZoaUrNeuCiWUxyc+wzucnEnFejUg3/A+CaF589k9qepLZZ1Jehnzig7YbD4hEuscGXuBY3fq+g==" + }, "http-errors": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", diff --git a/package.json b/package.json index d32fa63..d060d02 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "cors": "^2.8.5", "dotenv": "^16.0.0", "express": "^4.17.3", + "helmet": "^5.1.0", "oauth2-server": "^3.1.1", "passport": "^0.6.0", "passport-local": "^1.0.0", diff --git a/server.js b/server.js index 4063fa4..3f66ded 100644 --- a/server.js +++ b/server.js @@ -1,21 +1,25 @@ const express = require('express'); const cors = require('cors'); const app = express(); -const bodyParser = require('body-parser'); -const apiRouter = require('./routes/API'); + +const session = require('express-session'); require('dotenv').config({ path: './config.env' }); - const PORT = process.env.PORT; app.use(cors()); app.use(express.json()); -app.use(bodyParser.json()); -app.use(bodyParser.urlencoded({ +app.use(express.urlencoded({ extended: true })); +app.use(session({ + secret: 'secret', + cookie: { maxAge: 300000000, secure: false } +})) + +const apiRouter = require('./routes/API'); app.use(apiRouter); app.listen(PORT, () => {