From 6f4b70e2828547d957ea7bd3a5a1df915cbada70 Mon Sep 17 00:00:00 2001 From: Ron <66834451+SyniRon@users.noreply.github.com> Date: Sun, 3 Sep 2023 22:37:37 -0400 Subject: [PATCH] Formatting and minor work (#37) * prettier * remove .env from git * add linter * add eslint and build check * fix css for logo centering * remember to install * linter fix * maybe fix for eslint * remove unused extends * remove eslint * Fix prettier yaml * pin prettier version * fix formatting --- .github/workflows/build_check.yml | 43 ++ .github/workflows/lint_format.yml | 28 + .github/workflows/prod_url_check.yml | 16 +- client/.env | 1 - client/.gitignore | 1 + client/package-lock.json | 2 +- client/package.json | 2 +- client/public/index.html | 30 +- client/public/manifest.json | 2 +- client/src/App.css | 215 +++--- client/src/App.js | 462 +++++++++---- client/src/App.test.js | 6 +- client/src/credentials/example_token.js | 5 +- client/src/index.css | 9 +- client/src/index.js | 12 +- client/src/index.module.css | 8 +- client/src/modules/Generic/ArrayBuilder.js | 8 +- client/src/modules/Generic/BilletBank.js | 727 +++++++++++++++++++-- client/src/modules/Generic/MilpacParse.js | 387 +++++------ client/src/reportWebVitals.js | 4 +- client/src/setupTests.js | 2 +- package.json | 2 +- server/controllers/cRequest.js | 14 +- server/controllers/cacheManager.js | 81 +-- server/controllers/rRequest.js | 16 +- server/credentials/example_token.js | 7 +- server/routes/index.js | 12 +- server/server.js | 35 +- 28 files changed, 1503 insertions(+), 634 deletions(-) create mode 100644 .github/workflows/build_check.yml create mode 100644 .github/workflows/lint_format.yml delete mode 100644 client/.env diff --git a/.github/workflows/build_check.yml b/.github/workflows/build_check.yml new file mode 100644 index 0000000..6d94484 --- /dev/null +++ b/.github/workflows/build_check.yml @@ -0,0 +1,43 @@ +# This is a basic workflow to help you get started with Actions + +name: BUILD_CHECK + +# Controls when the workflow will run +on: + pull_request: + branches: + - main + paths: + - ".github/workflows/client_adr_push.yml" + - "client/**" + - "config/client/**" + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # deployment + client_deployment: + # The type of runner that the job will run on + runs-on: ubuntu-latest + env: + REACT_APP_CLIENT_TOKEN: ${{ secrets.CLIENT_TOKEN }} + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - name: Checkout the Repo + uses: actions/checkout@v3 + + - name: Setup node.js + uses: actions/setup-node@v3 + + - name: Install Dependancies + run: npm i + working-directory: client + + - name: Update Browserlist + run: npx browserslist@latest --update-db + working-directory: client + + - name: Build Client to Prod + run: npm run build + working-directory: client diff --git a/.github/workflows/lint_format.yml b/.github/workflows/lint_format.yml new file mode 100644 index 0000000..91c498d --- /dev/null +++ b/.github/workflows/lint_format.yml @@ -0,0 +1,28 @@ +# This is a basic workflow to help you get started with Actions + +name: LINT_FORMAT_CHECK + +# Controls when the workflow will run +on: + pull_request: + branches: + - main + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # deployment + lint_format_check: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - name: Checkout the Repo + uses: actions/checkout@v3 + + - name: Prettiier + uses: creyD/prettier_action@v4.3 + with: + prettier_options: "--check {**/*,*}.{js,jsx,json,html,css,yml,yaml}" + prettier_version: "2.8.8" diff --git a/.github/workflows/prod_url_check.yml b/.github/workflows/prod_url_check.yml index 811cac0..6057da7 100644 --- a/.github/workflows/prod_url_check.yml +++ b/.github/workflows/prod_url_check.yml @@ -1,15 +1,15 @@ name: PROD_URL_CHECK on: - pull_request: - branches: [ main ] - paths: - - 'client/src/App.js' + pull_request: + branches: [main] + paths: + - "client/src/App.js" jobs: - check-url: - runs-on: ubuntu-latest - steps: + check-url: + runs-on: ubuntu-latest + steps: - name: Checkout code uses: actions/checkout@v2 - name: Check API URL @@ -19,4 +19,4 @@ jobs: exit 1 else echo "Production API URL is present and not commented out." - fi \ No newline at end of file + fi diff --git a/client/.env b/client/.env deleted file mode 100644 index 1551f96..0000000 --- a/client/.env +++ /dev/null @@ -1 +0,0 @@ -WDS_SOCKET_PORT=0 \ No newline at end of file diff --git a/client/.gitignore b/client/.gitignore index 0d92c3f..7f70aa0 100644 --- a/client/.gitignore +++ b/client/.gitignore @@ -19,6 +19,7 @@ credentials/token.js .env.development.local .env.test.local .env.production.local +client/.env npm-debug.log* yarn-debug.log* diff --git a/client/package-lock.json b/client/package-lock.json index da89d9a..6299861 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -27147,4 +27147,4 @@ "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==" } } -} \ No newline at end of file +} diff --git a/client/package.json b/client/package.json index 147a1ed..c0e7092 100644 --- a/client/package.json +++ b/client/package.json @@ -37,4 +37,4 @@ "last 1 safari version" ] } -} \ No newline at end of file +} diff --git a/client/public/index.html b/client/public/index.html index 3d455ef..8f5b2ca 100644 --- a/client/public/index.html +++ b/client/public/index.html @@ -1,19 +1,17 @@ + + + + + + + + 7th Cavalry ADR + - - - - - - - - 7th Cavalry ADR - - - - -
- - - \ No newline at end of file + + +
+ + diff --git a/client/public/manifest.json b/client/public/manifest.json index fc7ce89..080d6c7 100644 --- a/client/public/manifest.json +++ b/client/public/manifest.json @@ -22,4 +22,4 @@ "display": "standalone", "theme_color": "#000000", "background_color": "#ffffff" -} \ No newline at end of file +} diff --git a/client/src/App.css b/client/src/App.css index 5d6ad6d..c665dfd 100644 --- a/client/src/App.css +++ b/client/src/App.css @@ -1,192 +1,189 @@ .DepartmentContainer { - margin: auto; - min-width: 30%; - max-width: 30%; + margin: auto; + min-width: 30%; + max-width: 30%; } @media only screen and (max-width: 1000px) { - .DepartmentContainer { - min-width: 50%; - max-width: 95%; - } + .DepartmentContainer { + min-width: 50%; + max-width: 95%; + } } .p-nav-primary { - position: sticky; - top: 0; - z-index: 400; - background-color: #2e2e2e; - margin-bottom: 1.2em; + position: sticky; + top: 0; + z-index: 400; + background-color: #2e2e2e; + margin-bottom: 1.2em; } .p-nav { - display: block; - overflow-wrap: break-word; + display: block; + overflow-wrap: break-word; } .p-nav-logo { - align-self: center; - box-sizing: border-box; - display: block; - max-width: 220px; - line-height: 21px; - padding: 3px + align-self: center; + box-sizing: border-box; + display: block; + max-width: 220px; + line-height: 21px; + padding: 3px; } +/* commented out because it was causing the logo to be off center .p-nav-inner { - margin-left: 25%; -} + margin-left: 25%; +} */ .p-nav-scroller { - display: flex; - align-items: center; - justify-content: flex-start; + display: flex; + align-items: center; + justify-content: center; } .p-nav-png { - max-width: 220px; - max-height: 37.7167px; - flex: 1 1 auto; + max-width: 220px; + max-height: 37.7167px; + flex: 1 1 auto; } .p-nav-opposite { - text-align: right; - flex: 1 1 auto; - margin: 5px + text-align: right; + flex: 1 1 auto; + margin: 5px; } .p-nav-opposite-link { - color: #f1f1f1; - font-weight: bold; + color: #f1f1f1; + font-weight: bold; } .p-nav-png { - width: 220px; - height: 37.7167px; + width: 220px; + height: 37.7167px; } .p-nav-info p { - color: #ff0000; - /* Red text */ - font-size: 14px; - margin: 20px; + color: #ff0000; + /* Red text */ + font-size: 14px; + margin: 20px; } /* Mobile layout */ @media (max-width: 768px) { - .p-nav-scroller { - flex-direction: column; - align-items: center; - justify-content: center; - /* Center-align items vertically */ - } + .p-nav-scroller { + flex-direction: column; + align-items: center; + justify-content: center; + /* Center-align items vertically */ + } - .p-nav-info p { - margin-left: 0; - margin-top: 10px; - /* Add some space between the logo and the text */ - } + .p-nav-info p { + margin-left: 0; + margin-top: 10px; + /* Add some space between the logo and the text */ + } } .Title { - color: #f1f1f1; - font-size: x-large; - font-weight: bold; - border-width: 1px; - border-style: solid; - border-image: - linear-gradient(to right, - #ebc729, - transparent) 1 0%; - border-top: transparent; + color: #f1f1f1; + font-size: x-large; + font-weight: bold; + border-width: 1px; + border-style: solid; + border-image: linear-gradient(to right, #ebc729, transparent) 1 0%; + border-top: transparent; } @media only screen and (max-width: 1000px) { - .Title { - border-image: none; - border-color: #ebc729; - border-left: transparent; - border-right: transparent; - } + .Title { + border-image: none; + border-color: #ebc729; + border-left: transparent; + border-right: transparent; + } } /* This is a very hack-y way to make the borders look proper on mobile browsers. This is because the border image property does not appear to be properly supported with IOS' Safari */ .Subtitle { - color: #f1f1f1; - font-size: larger; - font-weight: bold; - padding-top: 15px; - padding-bottom: 15px; + color: #f1f1f1; + font-size: larger; + font-weight: bold; + padding-top: 15px; + padding-bottom: 15px; } .Title:hover { - text-decoration: none; - cursor: pointer; + text-decoration: none; + cursor: pointer; } - .HeaderContainer { - display: flex; + display: flex; } .Counter { - font-size: smaller; - padding-top: 20px; - padding-bottom: 15px; - margin-left: auto; + font-size: smaller; + padding-top: 20px; + padding-bottom: 15px; + margin-left: auto; } .ItemList table { - width: 100%; - margin-left: auto; - margin-right: auto; + width: 100%; + margin-left: auto; + margin-right: auto; } .ItemList thead { - display: none; + display: none; } .ItemList td { - padding-bottom: 7px; - padding-left: 10px; - width: 50%; + padding-bottom: 7px; + padding-left: 10px; + width: 50%; } a { - color: #ebc729; - text-decoration: none; + color: #ebc729; + text-decoration: none; } a:hover { - color: #ebc729; - text-decoration: underline; + color: #ebc729; + text-decoration: underline; } .Collapsible__trigger { - display: block; - position: relative; + display: block; + position: relative; } .Collapsible__trigger:after { - content: url('./style/themes/Chevron.png'); - position: absolute; - right: 0px; - top: 0px; - display: block; - transition: transform 300ms; - transform: rotateZ(90deg); + content: url("./style/themes/Chevron.png"); + position: absolute; + right: 0px; + top: 0px; + display: block; + transition: transform 300ms; + transform: rotateZ(90deg); - /* No idea why i have to do this stupidity. For some reason if I dont do this, this shit becomes off centered */ - transform-origin: 67% 67%; + /* No idea why i have to do this stupidity. For some reason if I dont do this, this shit becomes off centered */ + transform-origin: 67% 67%; } .Collapsible__trigger.is-open::after { - transform: rotateZ(180deg); - position: absolute; - right: 0px; - top: 0px; - - /* No idea why i have to do this stupidity. For some reason if I dont do this, this shit becomes off centered */ - transform-origin: 67% 67%; -} \ No newline at end of file + transform: rotateZ(180deg); + position: absolute; + right: 0px; + top: 0px; + + /* No idea why i have to do this stupidity. For some reason if I dont do this, this shit becomes off centered */ + transform-origin: 67% 67%; +} diff --git a/client/src/App.js b/client/src/App.js index 48ffcb9..50b546e 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -1,13 +1,12 @@ -import React, { useEffect, useState } from 'react'; -import './App.css'; -import Collapsible from 'react-collapsible'; -import lists from './modules/Generic/BilletBank'; -import MilpacParse from './modules/Generic/MilpacParse'; +import React, { useEffect, useState } from "react"; +import "./App.css"; +import Collapsible from "react-collapsible"; +import lists from "./modules/Generic/BilletBank"; +import MilpacParse from "./modules/Generic/MilpacParse"; const CLIENT_TOKEN = process.env.REACT_APP_CLIENT_TOKEN; // import {Helmet} from 'react-helmet'; function MilpacRequest() { - const [milpacList, setMilpacList] = useState([]); const [reserveList, setReserveList] = useState([]); const clscript = `` +`; useEffect(() => { async function fetchMilpacList() { try { - const requestUrl = 'https://bff.adr.7cav.us/roster/combat' - //const requestUrl = 'http://localhost:4000/roster/combat' //Use this for local hosting + const requestUrl = "https://bff.adr.7cav.us/roster/combat"; + //const requestUrl = "http://localhost:4000/roster/combat"; //Use this for local hosting const response = await fetch(requestUrl, { headers: { - 'Authorization': CLIENT_TOKEN - } + Authorization: CLIENT_TOKEN, + }, }); if (!response.ok) { - throw new Error('HTTP Error! status: ' + response.status); + throw new Error("HTTP Error! status: " + response.status); } const responseJSON = await response.json(); @@ -45,16 +44,16 @@ function MilpacRequest() { useEffect(() => { async function fetchReserveList() { try { - const requestUrl = 'https://bff.adr.7cav.us/roster/reserves' - //const requestUrl = 'http://localhost:4000/roster/reserves' //Use this for local hosting + const requestUrl = "https://bff.adr.7cav.us/roster/reserves"; + //const requestUrl = "http://localhost:4000/roster/reserves"; //Use this for local hosting const response = await fetch(requestUrl, { headers: { - 'Authorization': CLIENT_TOKEN - } + Authorization: CLIENT_TOKEN, + }, }); if (!response.ok) { - throw new Error('HTTP Error! status: ' + response.status); + throw new Error("HTTP Error! status: " + response.status); } const responseJSON = await response.json(); @@ -66,17 +65,15 @@ function MilpacRequest() { fetchReserveList(); }, []); - var milpacArray = [] + var milpacArray = []; milpacArray.push({ - "combat": milpacList, - "reserve": reserveList, - }) + combat: milpacList, + reserve: reserveList, + }); return ( -
-
+
+
-
-
- - +
+
+ +
-
- -
- -
-
- -
-
- -
-
- +
+ +
+ +
+
+ +
+
+ +
+
+
-
- -
- -
-
- -
-
- -
-
- +
+ +
+ +
+
+ +
+
+ +
+
+
-
- -
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- +
+ +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
-
- -
- -
-
- -
-
- -
-
- +
+ +
+ +
+
+ +
+
+ +
+
+
-
- -
- -
-
- -
-
- -
-
- +
+ +
+ +
+
+ +
+
+ +
+
+
-
- -
- -
-
- -
-
- -
-
- +
+ +
+ +
+
+ +
+
+ +
+
+
-
- -
- -
-
- -
-
- -
-
- +
+ +
+ +
+
+ +
+
+ +
+
+
- ) + ); } -export default MilpacRequest +export default MilpacRequest; diff --git a/client/src/App.test.js b/client/src/App.test.js index 1f03afe..9382b9a 100644 --- a/client/src/App.test.js +++ b/client/src/App.test.js @@ -1,7 +1,7 @@ -import { render, screen } from '@testing-library/react'; -import App from './App'; +import { render, screen } from "@testing-library/react"; +import App from "./App"; -test('renders learn react link', () => { +test("renders learn react link", () => { render(); const linkElement = screen.getByText(/learn react/i); expect(linkElement).toBeInTheDocument(); diff --git a/client/src/credentials/example_token.js b/client/src/credentials/example_token.js index b8dd377..67585e8 100644 --- a/client/src/credentials/example_token.js +++ b/client/src/credentials/example_token.js @@ -1,6 +1,5 @@ -const CLIENT_TOKEN = 'XXXXXXXX' +const CLIENT_TOKEN = "XXXXXXXX"; module.exports = CLIENT_TOKEN; - //rename this file as "token.js" when in use. -// should be in `../client/src/credentials/token.js` path. \ No newline at end of file +// should be in `../client/src/credentials/token.js` path. diff --git a/client/src/index.css b/client/src/index.css index c064fd9..7aa53a0 100644 --- a/client/src/index.css +++ b/client/src/index.css @@ -1,6 +1,8 @@ body { margin: 0; - font-family: "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; + font-family: "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, + "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", + "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; font-size: 13px; font-weight: 400; line-height: 1.5; @@ -9,12 +11,11 @@ body { background-repeat: no-repeat; background-size: 100%; background-attachment: fixed; - background-image: url('style/themes/7cav/page-bg2.png'); + background-image: url("style/themes/7cav/page-bg2.png"); align-content: space-evenly; } - code { - font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', + font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace; } diff --git a/client/src/index.js b/client/src/index.js index ef2edf8..ad9cbbb 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -1,14 +1,14 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import './index.css'; -import App from './App'; -import reportWebVitals from './reportWebVitals'; +import React from "react"; +import ReactDOM from "react-dom"; +import "./index.css"; +import App from "./App"; +import reportWebVitals from "./reportWebVitals"; ReactDOM.render( , - document.getElementById('root') + document.getElementById("root") ); // If you want to start measuring performance in your app, pass a function diff --git a/client/src/index.module.css b/client/src/index.module.css index 4c48ca6..7014247 100644 --- a/client/src/index.module.css +++ b/client/src/index.module.css @@ -1,5 +1,3 @@ - -.ListContainer{ - text-align: center; - } - \ No newline at end of file +.ListContainer { + text-align: center; +} diff --git a/client/src/modules/Generic/ArrayBuilder.js b/client/src/modules/Generic/ArrayBuilder.js index e2a2f1e..c09a9f2 100644 --- a/client/src/modules/Generic/ArrayBuilder.js +++ b/client/src/modules/Generic/ArrayBuilder.js @@ -1,12 +1,12 @@ //This is included to generate arrays for large ammounts of billets. This is otherwise unused in the final product -let countString = ''; +let countString = ""; let i = 629; let stopper = 644; - + do { countString = `${countString},'${i}'`; i++; } while (i <= stopper); - -console.log(countString) \ No newline at end of file + +console.log(countString); diff --git a/client/src/modules/Generic/BilletBank.js b/client/src/modules/Generic/BilletBank.js index 2240609..b874479 100644 --- a/client/src/modules/Generic/BilletBank.js +++ b/client/src/modules/Generic/BilletBank.js @@ -1,96 +1,691 @@ - //Regimental Staff -const regiCommand = ['1','2','3','4','5','6','9','10','60','62','676','743']; +const regiCommand = [ + "1", + "2", + "3", + "4", + "5", + "6", + "9", + "10", + "60", + "62", + "676", + "743", +]; //1-7 -const oneSevenCommand = ['178','179','180','530']; -const alpha1 = ['196','197','198','199','200','201','202','203','204','205','206','207','208','209','210','211','212','213','214','215','216','217','218','219','220','221','222','223','224','225','226'] -const bravo1 = ['227','228','229','230','231','232','233','234','235','236','237','238','239','240','241','242','243','244','245','246','247','248','249','250','251','252','253','254','255','256','257','258','259','260','261','262','263','264','265','266','267','268','269','270','271','272','273','274','275','276','277','278','279','280','281','282','283','284','285']; -const charlie1 = ['286','287','288','289','290','291','292','293','294','295','296','297','298','299','300','301','302','303','304','305','306','307','308','309','310','311','312','313','314','315','316','317','318','319','320','321','322','323','324','325','326','327','328','329','330','331','332','333','334','335','336','337','338','339','340','341','342','343','344']; +const oneSevenCommand = ["178", "179", "180", "530"]; +const alpha1 = [ + "196", + "197", + "198", + "199", + "200", + "201", + "202", + "203", + "204", + "205", + "206", + "207", + "208", + "209", + "210", + "211", + "212", + "213", + "214", + "215", + "216", + "217", + "218", + "219", + "220", + "221", + "222", + "223", + "224", + "225", + "226", +]; +const bravo1 = [ + "227", + "228", + "229", + "230", + "231", + "232", + "233", + "234", + "235", + "236", + "237", + "238", + "239", + "240", + "241", + "242", + "243", + "244", + "245", + "246", + "247", + "248", + "249", + "250", + "251", + "252", + "253", + "254", + "255", + "256", + "257", + "258", + "259", + "260", + "261", + "262", + "263", + "264", + "265", + "266", + "267", + "268", + "269", + "270", + "271", + "272", + "273", + "274", + "275", + "276", + "277", + "278", + "279", + "280", + "281", + "282", + "283", + "284", + "285", +]; +const charlie1 = [ + "286", + "287", + "288", + "289", + "290", + "291", + "292", + "293", + "294", + "295", + "296", + "297", + "298", + "299", + "300", + "301", + "302", + "303", + "304", + "305", + "306", + "307", + "308", + "309", + "310", + "311", + "312", + "313", + "314", + "315", + "316", + "317", + "318", + "319", + "320", + "321", + "322", + "323", + "324", + "325", + "326", + "327", + "328", + "329", + "330", + "331", + "332", + "333", + "334", + "335", + "336", + "337", + "338", + "339", + "340", + "341", + "342", + "343", + "344", +]; //2-7 -const twoSevenCommand = ['182','183','184']; -const alpha2 = ['345','346','347','348','349','350','351','352','353','354','355','356','357','358','359','360','361','362','363','364','365','366','367','368','369','370','371','372','373','374','375','376','377','378','379','380','381','382','383','384','385','386','387','388','389','649','650','651','652','653','654']; -const bravo2 = ['390','391','392','393','394','395','396','397','398','399','400','401','402','403','404','405','406','407','408','409','410','411','412','413','414','415','416','417','418','419','420','421','422','423','424','425','426','427','428','429','430','431','432','433','434']; -const charlie2 = ['435','436','437','438','439','440','441','442','443','444','445','446','447','448','449','450','451','452','453','454','455','456','457','458','459','460','461','462','463','464','465','466','467','468','469','470','471','472','473','474','475','476','477','478','479']; +const twoSevenCommand = ["182", "183", "184"]; +const alpha2 = [ + "345", + "346", + "347", + "348", + "349", + "350", + "351", + "352", + "353", + "354", + "355", + "356", + "357", + "358", + "359", + "360", + "361", + "362", + "363", + "364", + "365", + "366", + "367", + "368", + "369", + "370", + "371", + "372", + "373", + "374", + "375", + "376", + "377", + "378", + "379", + "380", + "381", + "382", + "383", + "384", + "385", + "386", + "387", + "388", + "389", + "649", + "650", + "651", + "652", + "653", + "654", +]; +const bravo2 = [ + "390", + "391", + "392", + "393", + "394", + "395", + "396", + "397", + "398", + "399", + "400", + "401", + "402", + "403", + "404", + "405", + "406", + "407", + "408", + "409", + "410", + "411", + "412", + "413", + "414", + "415", + "416", + "417", + "418", + "419", + "420", + "421", + "422", + "423", + "424", + "425", + "426", + "427", + "428", + "429", + "430", + "431", + "432", + "433", + "434", +]; +const charlie2 = [ + "435", + "436", + "437", + "438", + "439", + "440", + "441", + "442", + "443", + "444", + "445", + "446", + "447", + "448", + "449", + "450", + "451", + "452", + "453", + "454", + "455", + "456", + "457", + "458", + "459", + "460", + "461", + "462", + "463", + "464", + "465", + "466", + "467", + "468", + "469", + "470", + "471", + "472", + "473", + "474", + "475", + "476", + "477", + "478", + "479", +]; //ACD -const acdCommand = ['552','627','645','11']; -const alpha3 = ['555','556','557','558','559','560','561','562','563','564','565','566','567','568','569','570','571','572','573','574','683','684','685','686','687','688','689','690','691','692','693','694','695','696','691','760','761','747','748','750','762','763','764','765','766','767','768','769','770']; -const bravo3 = ['590','591','592','593','594','595','596','597','598','599','600','601','602','603','604','605','606','607','608','609','610','611','612','613','614','615','616','617','618','619','620','621','622','623','624','625','626']; -const charlie3 = ['656','657','658','659','660','661','662','663','664','665','666','667','668','669','670','671','672']; -const delta3 = ['538','698','699','700','701','702','704','705','706','712','713','714','715','716','717','718','719','720','707','708','709','710','711','721','722','723','724','725','726','727','728','729','739','740','741']; +const acdCommand = ["552", "627", "645", "11"]; +const alpha3 = [ + "555", + "556", + "557", + "558", + "559", + "560", + "561", + "562", + "563", + "564", + "565", + "566", + "567", + "568", + "569", + "570", + "571", + "572", + "573", + "574", + "683", + "684", + "685", + "686", + "687", + "688", + "689", + "690", + "691", + "692", + "693", + "694", + "695", + "696", + "691", + "760", + "761", + "747", + "748", + "750", + "762", + "763", + "764", + "765", + "766", + "767", + "768", + "769", + "770", +]; +const bravo3 = [ + "590", + "591", + "592", + "593", + "594", + "595", + "596", + "597", + "598", + "599", + "600", + "601", + "602", + "603", + "604", + "605", + "606", + "607", + "608", + "609", + "610", + "611", + "612", + "613", + "614", + "615", + "616", + "617", + "618", + "619", + "620", + "621", + "622", + "623", + "624", + "625", + "626", +]; +const charlie3 = [ + "656", + "657", + "658", + "659", + "660", + "661", + "662", + "663", + "664", + "665", + "666", + "667", + "668", + "669", + "670", + "671", + "672", +]; +const delta3 = [ + "538", + "698", + "699", + "700", + "701", + "702", + "704", + "705", + "706", + "712", + "713", + "714", + "715", + "716", + "717", + "718", + "719", + "720", + "707", + "708", + "709", + "710", + "711", + "721", + "722", + "723", + "724", + "725", + "726", + "727", + "728", + "729", + "739", + "740", + "741", +]; const echo3 = []; -const starterPlatoon = ['759']; -const futureC = ['753']; +const starterPlatoon = ["759"]; +const futureC = ["753"]; //IMO -const imoCommand = ['5','9']; -const s1 = ['7','8','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37']; -const s6 = ['50','51','52','53','54','55','56','57','58','59']; -const wag = ['39','40','41','42','43','44','45','46','47','48']; +const imoCommand = ["5", "9"]; +const s1 = [ + "7", + "8", + "17", + "18", + "19", + "20", + "21", + "22", + "23", + "24", + "25", + "26", + "27", + "28", + "29", + "30", + "31", + "32", + "33", + "34", + "35", + "36", + "37", +]; +const s6 = ["50", "51", "52", "53", "54", "55", "56", "57", "58", "59"]; +const wag = ["39", "40", "41", "42", "43", "44", "45", "46", "47", "48"]; //ROO -const rooCommand = ['4','60']; -const rrd = ['64','65','577','578','579','580','751','734','736','738']; -const rtc = ['98','99','100','101','102','103']; -const s5 = ['83','84','85','86','87','88','89','90','91','92','93','94','95','96','739','740','741']; +const rooCommand = ["4", "60"]; +const rrd = [ + "64", + "65", + "577", + "578", + "579", + "580", + "751", + "734", + "736", + "738", +]; +const rtc = ["98", "99", "100", "101", "102", "103"]; +const s5 = [ + "83", + "84", + "85", + "86", + "87", + "88", + "89", + "90", + "91", + "92", + "93", + "94", + "95", + "96", + "739", + "740", + "741", +]; //SecOps -const secOpsCommand = ['2','62']; //Interesting case for Kleinmen, will need to be renamed to a new billetID if he ever leaves -const jag = ['584']; -const mp = ['168','169','170','171','172','173']; -const s2 = ['161','162','163','164','165','166']; +const secOpsCommand = ["2", "62"]; //Interesting case for Kleinmen, will need to be renamed to a new billetID if he ever leaves +const jag = ["584"]; +const mp = ["168", "169", "170", "171", "172", "173"]; +const s2 = ["161", "162", "163", "164", "165", "166"]; //Support -const s3 = ['134','135','136','137','138','139','140','141','142','143','144','145','146','147','148','149','150','151','152','153','154','155','156','157','158','159','540','541','542','543', '673', '674','673','674','675','646','647','648']; +const s3 = [ + "134", + "135", + "136", + "137", + "138", + "139", + "140", + "141", + "142", + "143", + "144", + "145", + "146", + "147", + "148", + "149", + "150", + "151", + "152", + "153", + "154", + "155", + "156", + "157", + "158", + "159", + "540", + "541", + "542", + "543", + "673", + "674", + "673", + "674", + "675", + "646", + "647", + "648", +]; -const s7 = ['105','106','107','108','109','110','111','112','113','114','115','116','117','118','119','120','121','122','123','124','125','531','532','533','534','535','536','537','544','545','546','547','548','549','550','551','629','630','631','632','633','634','635','636','637','638','639','640','641','642','643','644']; -const ld =['126','127','128','129','130','131','132','539']; //I think... -const spd = ['175','176']; +const s7 = [ + "105", + "106", + "107", + "108", + "109", + "110", + "111", + "112", + "113", + "114", + "115", + "116", + "117", + "118", + "119", + "120", + "121", + "122", + "123", + "124", + "125", + "531", + "532", + "533", + "534", + "535", + "536", + "537", + "544", + "545", + "546", + "547", + "548", + "549", + "550", + "551", + "629", + "630", + "631", + "632", + "633", + "634", + "635", + "636", + "637", + "638", + "639", + "640", + "641", + "642", + "643", + "644", +]; +const ld = ["126", "127", "128", "129", "130", "131", "132", "539"]; //I think... +const spd = ["175", "176"]; const billetBank = { - regiCommand, - oneSevenCommand, - alpha1, - bravo1, - charlie1, - twoSevenCommand, - alpha2, - bravo2, - charlie2, - acdCommand, - alpha3, - bravo3, - charlie3, - delta3, - echo3, - starterPlatoon, - futureC, - imoCommand, - s1, - s6, - wag, - rooCommand, - rrd, - rtc, - s5, - secOpsCommand, - jag, - mp, - s2, - s3, - s7, - spd, - ld, + regiCommand, + oneSevenCommand, + alpha1, + bravo1, + charlie1, + twoSevenCommand, + alpha2, + bravo2, + charlie2, + acdCommand, + alpha3, + bravo3, + charlie3, + delta3, + echo3, + starterPlatoon, + futureC, + imoCommand, + s1, + s6, + wag, + rooCommand, + rrd, + rtc, + s5, + secOpsCommand, + jag, + mp, + s2, + s3, + s7, + spd, + ld, }; export default billetBank; diff --git a/client/src/modules/Generic/MilpacParse.js b/client/src/modules/Generic/MilpacParse.js index 65f1de2..3a8ac66 100644 --- a/client/src/modules/Generic/MilpacParse.js +++ b/client/src/modules/Generic/MilpacParse.js @@ -1,195 +1,202 @@ -import React from 'react'; - -function MilpacParse (props) { - var array = []; - var milpacArray = props.milpacArray - var billetIDs = props.billetIDs - var usePrimaryOnly = props.usePrimaryOnly - var subtitle = props.subtitle - - if (usePrimaryOnly !== true) { - - for (var milpacIdCombat in milpacArray[0].combat.profiles) { - - var name = milpacArray[0].combat.profiles[milpacIdCombat].realName; - var rank = milpacArray[0].combat.profiles[milpacIdCombat].rank.rankFull - var primary = milpacArray[0].combat.profiles[milpacIdCombat].primary; - var fullName = rank + ' ' + name; - var primarySortKey = milpacArray[0].combat.profiles[milpacIdCombat].primary.positionId; - - if (billetIDs.includes(primary.positionId)) { - - array.push({ - "fullName": fullName, - "position": primary, - "isPrimary": 'true', - "sortKey": primarySortKey, - "itemKey": milpacIdCombat, - "listKey": primarySortKey + milpacIdCombat - }) - } - - for (var index in milpacArray[0].combat.profiles[milpacIdCombat].secondaries) { - var secondary = milpacArray[0].combat.profiles[milpacIdCombat].secondaries[index] - var secondarySortKey = milpacArray[0].combat.profiles[milpacIdCombat].secondaries[index].positionId; - - if (!billetIDs.includes(secondary.positionId)) { - continue; - } - - array.push({ - "fullName": fullName, - "position": secondary, - "isPrimary": 'false', - "sortKey": secondarySortKey, - "itemKey": milpacIdCombat, - "listKey": secondarySortKey + milpacIdCombat - }) - } - }; - - for (var milpacIdReserve in milpacArray[0].reserve.profiles) { - - var rName = milpacArray[0].reserve.profiles[milpacIdReserve].realName; - var rRank = milpacArray[0].reserve.profiles[milpacIdReserve].rank.rankFull - var rPrimary = milpacArray[0].reserve.profiles[milpacIdReserve].primary; - var rFullName = rRank + ' ' + rName; - var rPrimarySortKey = milpacArray[0].reserve.profiles[milpacIdReserve].primary.positionId; - - if (billetIDs.includes(rPrimary.positionId)) { - - array.push({ - "fullName": rFullName, - "position": rPrimary, - "isPrimary": 'true', - "sortKey": rPrimarySortKey, - "itemKey": milpacIdReserve, - "listKey": rPrimarySortKey + milpacIdReserve - }) - } - - for (var rIndex in milpacArray[0].reserve.profiles[milpacIdReserve].secondaries) { - var rSecondary = milpacArray[0].reserve.profiles[milpacIdReserve].secondaries[rIndex] - var rSecondarySortKey = milpacArray[0].reserve.profiles[milpacIdReserve].secondaries[rIndex].positionId; - - if (!billetIDs.includes(rSecondary.positionId)) { - continue; - } - - array.push({ - "fullName": rFullName, - "position": rSecondary, - "isPrimary": 'false', - "sortKey": rSecondarySortKey, - "itemKey": milpacIdReserve, - "listKey": rSecondarySortKey + milpacIdReserve - }) - } - }; - - // Sorting the array based on the order of positionIds in the billetIDs array - array.sort((a, b) => { - const aIndex = billetIDs.indexOf(a.sortKey); - const bIndex = billetIDs.indexOf(b.sortKey); - return aIndex - bIndex; +import React from "react"; + +function MilpacParse(props) { + var array = []; + var milpacArray = props.milpacArray; + var billetIDs = props.billetIDs; + var usePrimaryOnly = props.usePrimaryOnly; + var subtitle = props.subtitle; + + if (usePrimaryOnly !== true) { + for (var milpacIdCombat in milpacArray[0].combat.profiles) { + var name = milpacArray[0].combat.profiles[milpacIdCombat].realName; + var rank = milpacArray[0].combat.profiles[milpacIdCombat].rank.rankFull; + var primary = milpacArray[0].combat.profiles[milpacIdCombat].primary; + var fullName = rank + " " + name; + var primarySortKey = + milpacArray[0].combat.profiles[milpacIdCombat].primary.positionId; + + if (billetIDs.includes(primary.positionId)) { + array.push({ + fullName: fullName, + position: primary, + isPrimary: "true", + sortKey: primarySortKey, + itemKey: milpacIdCombat, + listKey: primarySortKey + milpacIdCombat, }); - - return( -
-
-
- {subtitle} -
-
- Unit Strength: {array.length} -
-
-
- - - - - - - - - {array.map( obj => { - return( - - - - - ) - })} - -
NameBillet
{obj.fullName}{obj.position.positionTitle}
-
-
- ) - } else if (usePrimaryOnly === true) { - - for (milpacIdCombat in milpacArray[0].combat.profiles) { - - name = milpacArray[0].combat.profiles[milpacIdCombat].realName; - rank = milpacArray[0].combat.profiles[milpacIdCombat].rank.rankFull - primary = milpacArray[0].combat.profiles[milpacIdCombat].primary; - fullName = rank + ' ' + name; - primarySortKey = milpacArray[0].combat.profiles[milpacIdCombat].primary.positionId; - - if (billetIDs.includes(primary.positionId)) { - - array.push({ - "fullName": fullName, - "position": primary, - "isPrimary": 'true', - "sortKey": primarySortKey, - "itemKey": milpacIdCombat, - "listKey": primarySortKey + milpacIdCombat - }) - } - }; - - // Sorting the array based on the order of positionIds in the billetIDs array - array.sort((a, b) => { - const aIndex = billetIDs.indexOf(a.sortKey); - const bIndex = billetIDs.indexOf(b.sortKey); - return aIndex - bIndex; + } + + for (var index in milpacArray[0].combat.profiles[milpacIdCombat] + .secondaries) { + var secondary = + milpacArray[0].combat.profiles[milpacIdCombat].secondaries[index]; + var secondarySortKey = + milpacArray[0].combat.profiles[milpacIdCombat].secondaries[index] + .positionId; + + if (!billetIDs.includes(secondary.positionId)) { + continue; + } + + array.push({ + fullName: fullName, + position: secondary, + isPrimary: "false", + sortKey: secondarySortKey, + itemKey: milpacIdCombat, + listKey: secondarySortKey + milpacIdCombat, }); - - - return( -
-
-
- {subtitle} -
-
- Unit Strength: {array.length} -
-
-
- - - - - - - - - {array.map( obj => { - return( - - - - - ) - })} - -
NameBillet
{obj.fullName}{obj.position.positionTitle}
-
-
- ) + } } + + for (var milpacIdReserve in milpacArray[0].reserve.profiles) { + var rName = milpacArray[0].reserve.profiles[milpacIdReserve].realName; + var rRank = + milpacArray[0].reserve.profiles[milpacIdReserve].rank.rankFull; + var rPrimary = milpacArray[0].reserve.profiles[milpacIdReserve].primary; + var rFullName = rRank + " " + rName; + var rPrimarySortKey = + milpacArray[0].reserve.profiles[milpacIdReserve].primary.positionId; + + if (billetIDs.includes(rPrimary.positionId)) { + array.push({ + fullName: rFullName, + position: rPrimary, + isPrimary: "true", + sortKey: rPrimarySortKey, + itemKey: milpacIdReserve, + listKey: rPrimarySortKey + milpacIdReserve, + }); + } + + for (var rIndex in milpacArray[0].reserve.profiles[milpacIdReserve] + .secondaries) { + var rSecondary = + milpacArray[0].reserve.profiles[milpacIdReserve].secondaries[rIndex]; + var rSecondarySortKey = + milpacArray[0].reserve.profiles[milpacIdReserve].secondaries[rIndex] + .positionId; + + if (!billetIDs.includes(rSecondary.positionId)) { + continue; + } + + array.push({ + fullName: rFullName, + position: rSecondary, + isPrimary: "false", + sortKey: rSecondarySortKey, + itemKey: milpacIdReserve, + listKey: rSecondarySortKey + milpacIdReserve, + }); + } + } + + // Sorting the array based on the order of positionIds in the billetIDs array + array.sort((a, b) => { + const aIndex = billetIDs.indexOf(a.sortKey); + const bIndex = billetIDs.indexOf(b.sortKey); + return aIndex - bIndex; + }); + + return ( +
+
+
{subtitle}
+
Unit Strength: {array.length}
+
+
+ + + + + + + + + {array.map((obj) => { + return ( + + + + + ); + })} + +
NameBillet
+ + {obj.fullName} + + {obj.position.positionTitle}
+
+
+ ); + } else if (usePrimaryOnly === true) { + for (milpacIdCombat in milpacArray[0].combat.profiles) { + name = milpacArray[0].combat.profiles[milpacIdCombat].realName; + rank = milpacArray[0].combat.profiles[milpacIdCombat].rank.rankFull; + primary = milpacArray[0].combat.profiles[milpacIdCombat].primary; + fullName = rank + " " + name; + primarySortKey = + milpacArray[0].combat.profiles[milpacIdCombat].primary.positionId; + + if (billetIDs.includes(primary.positionId)) { + array.push({ + fullName: fullName, + position: primary, + isPrimary: "true", + sortKey: primarySortKey, + itemKey: milpacIdCombat, + listKey: primarySortKey + milpacIdCombat, + }); + } + } + + // Sorting the array based on the order of positionIds in the billetIDs array + array.sort((a, b) => { + const aIndex = billetIDs.indexOf(a.sortKey); + const bIndex = billetIDs.indexOf(b.sortKey); + return aIndex - bIndex; + }); + + return ( +
+
+
{subtitle}
+
Unit Strength: {array.length}
+
+
+ + + + + + + + + {array.map((obj) => { + return ( + + + + + ); + })} + +
NameBillet
+ + {obj.fullName} + + {obj.position.positionTitle}
+
+
+ ); + } } -export default MilpacParse; \ No newline at end of file +export default MilpacParse; diff --git a/client/src/reportWebVitals.js b/client/src/reportWebVitals.js index 5253d3a..9ecd33f 100644 --- a/client/src/reportWebVitals.js +++ b/client/src/reportWebVitals.js @@ -1,6 +1,6 @@ -const reportWebVitals = onPerfEntry => { +const reportWebVitals = (onPerfEntry) => { if (onPerfEntry && onPerfEntry instanceof Function) { - import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { + import("web-vitals").then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { getCLS(onPerfEntry); getFID(onPerfEntry); getFCP(onPerfEntry); diff --git a/client/src/setupTests.js b/client/src/setupTests.js index 8f2609b..1dd407a 100644 --- a/client/src/setupTests.js +++ b/client/src/setupTests.js @@ -2,4 +2,4 @@ // allows you to do things like: // expect(element).toHaveTextContent(/react/i) // learn more: https://github.com/testing-library/jest-dom -import '@testing-library/jest-dom'; +import "@testing-library/jest-dom"; diff --git a/package.json b/package.json index 03153cf..9cbafba 100644 --- a/package.json +++ b/package.json @@ -19,4 +19,4 @@ "react-collapsible": "^2.8.4", "react-helmet": "^6.1.0" } -} \ No newline at end of file +} diff --git a/server/controllers/cRequest.js b/server/controllers/cRequest.js index 90979a8..11764c3 100644 --- a/server/controllers/cRequest.js +++ b/server/controllers/cRequest.js @@ -1,11 +1,11 @@ -const cacheManager = require('../controllers/cacheManager'); +const cacheManager = require("../controllers/cacheManager"); module.exports = async (req, res) => { - const cachedCombatRoster = cacheManager.getCachedCombatRoster(); + const cachedCombatRoster = cacheManager.getCachedCombatRoster(); - if (cachedCombatRoster) { - res.send(cachedCombatRoster); - } else { - res.status(503).send("Cache is empty"); - } + if (cachedCombatRoster) { + res.send(cachedCombatRoster); + } else { + res.status(503).send("Cache is empty"); + } }; diff --git a/server/controllers/cacheManager.js b/server/controllers/cacheManager.js index c53e530..02e22cf 100644 --- a/server/controllers/cacheManager.js +++ b/server/controllers/cacheManager.js @@ -6,62 +6,63 @@ let cachedReserveRoster; let cacheTime = {}; const updateCombatRosterCache = async () => { - try { - const response = await axios('https://api.7cav.us/api/v1/roster/1', { - headers: { - Accept: 'application/json', - 'Content-Type': 'application/json', - Authorization: 'Bearer ' + API_TOKEN - }, - }); - cachedCombatRoster = response.data; - cacheTime['combat'] = Date.now(); - } catch (error) { - console.error("Failed to update combat cache:", error); - } + try { + const response = await axios("https://api.7cav.us/api/v1/roster/1", { + headers: { + Accept: "application/json", + "Content-Type": "application/json", + Authorization: "Bearer " + API_TOKEN, + }, + }); + cachedCombatRoster = response.data; + cacheTime["combat"] = Date.now(); + } catch (error) { + console.error("Failed to update combat cache:", error); + } }; const updateReserveRosterCache = async () => { - try { - const response = await axios('https://api.7cav.us/api/v1/roster/2', { - headers: { - Accept: 'application/json', - 'Content-Type': 'application/json', - Authorization: 'Bearer ' + API_TOKEN - }, - }); - cachedReserveRoster = response.data; - cacheTime['reserve'] = Date.now(); - } catch (error) { - console.error("Failed to update reserve cache:", error); - } + try { + const response = await axios("https://api.7cav.us/api/v1/roster/2", { + headers: { + Accept: "application/json", + "Content-Type": "application/json", + Authorization: "Bearer " + API_TOKEN, + }, + }); + cachedReserveRoster = response.data; + cacheTime["reserve"] = Date.now(); + } catch (error) { + console.error("Failed to update reserve cache:", error); + } }; -const scheduleCacheUpdate = (updateFunction, key) => { - const now = new Date(); - const delay = (60 - now.getMinutes()) * 60 * 1000 + (60 - now.getSeconds()) * 1000; +const scheduleCacheUpdate = (updateFunction) => { + const now = new Date(); + const delay = + (60 - now.getMinutes()) * 60 * 1000 + (60 - now.getSeconds()) * 1000; - setTimeout(() => { - updateFunction(); - setInterval(updateFunction, 3660 * 1000); // Update every 3660 seconds (1 hour and 1 minute) - }, delay); + setTimeout(() => { + updateFunction(); + setInterval(updateFunction, 3660 * 1000); // Update every 3660 seconds (1 hour and 1 minute) + }, delay); }; // Initialize the cache and schedule the updates updateCombatRosterCache(); -scheduleCacheUpdate(updateCombatRosterCache, 'combat'); +scheduleCacheUpdate(updateCombatRosterCache); updateReserveRosterCache(); -scheduleCacheUpdate(updateReserveRosterCache, 'reserve'); +scheduleCacheUpdate(updateReserveRosterCache); const getCachedCombatRoster = () => { - return cachedCombatRoster; + return cachedCombatRoster; }; const getCachedReserveRoster = () => { - return cachedReserveRoster; + return cachedReserveRoster; }; module.exports = { - getCachedCombatRoster, - getCachedReserveRoster -}; \ No newline at end of file + getCachedCombatRoster, + getCachedReserveRoster, +}; diff --git a/server/controllers/rRequest.js b/server/controllers/rRequest.js index 8ad0445..fbcaa68 100644 --- a/server/controllers/rRequest.js +++ b/server/controllers/rRequest.js @@ -1,11 +1,11 @@ -const cacheManager = require('../controllers/cacheManager'); +const cacheManager = require("../controllers/cacheManager"); module.exports = async (req, res) => { - const cachedReserveRoster = cacheManager.getCachedReserveRoster(); + const cachedReserveRoster = cacheManager.getCachedReserveRoster(); - if (cachedReserveRoster) { - res.send(cachedReserveRoster); - } else { - res.status(503).send("Cache is empty"); - } -}; \ No newline at end of file + if (cachedReserveRoster) { + res.send(cachedReserveRoster); + } else { + res.status(503).send("Cache is empty"); + } +}; diff --git a/server/credentials/example_token.js b/server/credentials/example_token.js index edc917f..6ae11a2 100644 --- a/server/credentials/example_token.js +++ b/server/credentials/example_token.js @@ -1,7 +1,6 @@ -const API_TOKEN = 'XXXXXXXXXXX' -const CLIENT_TOKEN = 'XXXXXXXX' +const API_TOKEN = "XXXXXXXXXXX"; +const CLIENT_TOKEN = "XXXXXXXX"; module.exports = { API_TOKEN, CLIENT_TOKEN }; - //rename this file as "token.js" when in use. -// should be in `../server/credentials/token.js` path. \ No newline at end of file +// should be in `../server/credentials/token.js` path. diff --git a/server/routes/index.js b/server/routes/index.js index 052e238..b5d4f5f 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -1,14 +1,16 @@ const express = require("express"); const router = express.Router(); -const cors = require('cors'); +const cors = require("cors"); const cRequest = require("../controllers/cRequest"); const rRequest = require("../controllers/rRequest"); const app = express(); -app.use(cors({ - origin: '*', -})); +app.use( + cors({ + origin: "*", + }) +); router.get("/combat", cRequest); router.get("/reserves", rRequest); -module.exports = router; \ No newline at end of file +module.exports = router; diff --git a/server/server.js b/server/server.js index 601e66d..4bc49c2 100644 --- a/server/server.js +++ b/server/server.js @@ -1,40 +1,49 @@ const middleware = require("./routes"); const express = require("express"); -const app = express() +const app = express(); const cors = require("cors"); const port = 4000; const { CLIENT_TOKEN } = require("./credentials/token"); const corsOptions = { origin: function (origin, callback) { - const allowlist = ["http://localhost:3000", "http://adr.7cav.us", "https://adr.7cav.us", "https://adr.7cav.us/"]; + const allowlist = [ + "http://localhost:3000", + "http://adr.7cav.us", + "https://adr.7cav.us", + "https://adr.7cav.us/", + ]; if (allowlist.indexOf(origin) !== -1 || !origin) { callback(null, true); } else { callback(new Error("Not allowed by CORS")); } - } -} + }, +}; // Token Checking Middleware const checkToken = (req, res, next) => { - const authToken = req.headers['authorization']; + const authToken = req.headers["authorization"]; if (authToken === CLIENT_TOKEN) { - next(); // proceed to the next middleware or route handler + next(); // proceed to the next middleware or route handler } else { - res.status(403).send('Forbidden'); + res.status(403).send("Forbidden"); } }; -app.use(cors({ - origin: corsOptions.origin, -})); +app.use( + cors({ + origin: corsOptions.origin, + }) +); // Apply token checking middleware only to these routes app.use("/roster", checkToken, middleware); app.get("/", (req, res) => { - res.send("Server Test Page Loaded Successfully. Any issues? Submit a ticket to S6! Frontend is at https://adr.7cav.us/"); + res.send( + "Server Test Page Loaded Successfully. Any issues? Submit a ticket to S6! Frontend is at https://adr.7cav.us/" + ); }); app.listen(port, () => { - console.log(`Roster Server listening on ${port}`) -}) + console.log(`Roster Server listening on ${port}`); +});