Compare commits
112 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2964c1e448 | |||
| a2344947f8 | |||
| 52b755fe16 | |||
| b1c31731ee | |||
| b8cc43c556 | |||
| 24b9ff3b5f | |||
| a38b8922a0 | |||
| fcedc00612 | |||
| da4316dccc | |||
| faacb8b8c7 | |||
| c48fcba994 | |||
| 56e3151db0 | |||
| 8aeaa46332 | |||
| cd34f0db5c | |||
| ab9e7456fb | |||
| 90a4fc1a6a | |||
| 42fa9e27e7 | |||
| 0c462d0e6c | |||
| fce018d19b | |||
| 6717dbdef6 | |||
| 39c3e55bd5 | |||
| c4c836edb7 | |||
| fe089e13f1 | |||
| c3a322fe2a | |||
| bac1063de5 | |||
| 2dcafd200d | |||
| a18ea7fe67 | |||
| b6e8d7ad7a | |||
| 1c4d87622c | |||
| 2d9f29e694 | |||
| 4b6eb2271c | |||
| 56fc50d3b9 | |||
| d29e3397a6 | |||
| 335c7008aa | |||
| e89b0645ca | |||
| 36e79a513f | |||
| 6ef0affcf6 | |||
| cb0c1284bf | |||
| 5cf4b66894 | |||
| 45cf281c91 | |||
| 2794b4c724 | |||
| b1f49a4166 | |||
| 4cbf67dcbb | |||
| fd29385cf8 | |||
| 8e81dccef6 | |||
| adeb8c4267 | |||
| eb6c3a40d7 | |||
| 4d4a0b5401 | |||
| 490860159e | |||
| ed01fe6db5 | |||
| cfb8d20ad2 | |||
| d44cae397d | |||
| b97fff05b3 | |||
| 22703bfbcb | |||
| 14a3c9eabe | |||
| 8e90a4a540 | |||
| 1d3c94a1aa | |||
| ca5e79ccf3 | |||
| 03acce1907 | |||
| c0b7280533 | |||
| 2925cce7ca | |||
| b90670b922 | |||
| 290f25f898 | |||
| 3cdef433f9 | |||
| 53c8ddab54 | |||
| 4e94c5338d | |||
| 55ff5765c6 | |||
| d486059430 | |||
| 9d8c948dbb | |||
| b21fa8db9e | |||
| c130b74e2d | |||
| d37b93d5f7 | |||
| 829cb2e3da | |||
| 29f0dbb1ca | |||
| 13ad7d2435 | |||
| e30853e0cd | |||
| 1e16a96f86 | |||
| cff73107b2 | |||
| 76417747b3 | |||
| b8323723ed | |||
| 415b2f32f1 | |||
| a0dbe0aee1 | |||
| f415a7ece2 | |||
| 9c863f309f | |||
| 7547b1717e | |||
| 22e6286e0a | |||
| c766c43223 | |||
| bb1590bae7 | |||
| 5f7b9dda3a | |||
| 051f3dfb2a | |||
| 85456e0892 | |||
| 6130337846 | |||
| ac99f3bf38 | |||
| 20e94db628 | |||
| bcb4a37f5a | |||
| 3b0d3c87b1 | |||
| 51a116503d | |||
| eb370663d2 | |||
| 462116d980 | |||
| af06ddc06d | |||
| f937ee47db | |||
| 6d0dd419ca | |||
| 2919467dff | |||
| 269caac88c | |||
| 69c297fa74 | |||
| 0f538be3e5 | |||
| f85b6e8793 | |||
| 2af9532930 | |||
| 191da50740 | |||
| f24c7990f6 | |||
| 7a48780f50 | |||
| 33952a9896 |
@@ -1,6 +1,8 @@
|
|||||||
WEB_PORT=3000
|
WEB_PORT=3000
|
||||||
|
|
||||||
DB_HOSTNAME=localhost
|
DB_HOSTNAME=localhost
|
||||||
|
DB_PORTNAME=3306
|
||||||
|
|
||||||
DB_DATABASE=template
|
DB_DATABASE=template
|
||||||
DB_USERNAME=template
|
DB_USERNAME=template
|
||||||
DB_PASSWORD=pikachu
|
DB_PASSWORD=pikachu
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
patreon: krgamestudios
|
||||||
|
ko_fi: krgamestudios
|
||||||
|
custom: ["https://www.paypal.com/donate/?hosted_button_id=73Q82T2ZHV8AA"]
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
||||||
|
|
||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "npm"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
|
|
||||||
|
|
||||||
+119
-118
@@ -1,118 +1,119 @@
|
|||||||
# Logs
|
# Logs
|
||||||
logs
|
logs
|
||||||
*.log
|
*.log
|
||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
lerna-debug.log*
|
lerna-debug.log*
|
||||||
|
|
||||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||||
|
|
||||||
# Runtime data
|
# Runtime data
|
||||||
pids
|
pids
|
||||||
*.pid
|
*.pid
|
||||||
*.seed
|
*.seed
|
||||||
*.pid.lock
|
*.pid.lock
|
||||||
|
|
||||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
lib-cov
|
lib-cov
|
||||||
|
|
||||||
# Coverage directory used by tools like istanbul
|
# Coverage directory used by tools like istanbul
|
||||||
coverage
|
coverage
|
||||||
*.lcov
|
*.lcov
|
||||||
|
|
||||||
# nyc test coverage
|
# nyc test coverage
|
||||||
.nyc_output
|
.nyc_output
|
||||||
|
|
||||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
.grunt
|
.grunt
|
||||||
|
|
||||||
# Bower dependency directory (https://bower.io/)
|
# Bower dependency directory (https://bower.io/)
|
||||||
bower_components
|
bower_components
|
||||||
|
|
||||||
# node-waf configuration
|
# node-waf configuration
|
||||||
.lock-wscript
|
.lock-wscript
|
||||||
|
|
||||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||||
build/Release
|
build/Release
|
||||||
|
|
||||||
# Dependency directories
|
# Dependency directories
|
||||||
node_modules/
|
node_modules/
|
||||||
jspm_packages/
|
jspm_packages/
|
||||||
|
|
||||||
# TypeScript v1 declaration files
|
# TypeScript v1 declaration files
|
||||||
typings/
|
typings/
|
||||||
|
|
||||||
# TypeScript cache
|
# TypeScript cache
|
||||||
*.tsbuildinfo
|
*.tsbuildinfo
|
||||||
|
|
||||||
# Optional npm cache directory
|
# Optional npm cache directory
|
||||||
.npm
|
.npm
|
||||||
|
|
||||||
# Optional eslint cache
|
# Optional eslint cache
|
||||||
.eslintcache
|
.eslintcache
|
||||||
|
|
||||||
# Microbundle cache
|
# Microbundle cache
|
||||||
.rpt2_cache/
|
.rpt2_cache/
|
||||||
.rts2_cache_cjs/
|
.rts2_cache_cjs/
|
||||||
.rts2_cache_es/
|
.rts2_cache_es/
|
||||||
.rts2_cache_umd/
|
.rts2_cache_umd/
|
||||||
|
|
||||||
# Optional REPL history
|
# Optional REPL history
|
||||||
.node_repl_history
|
.node_repl_history
|
||||||
|
|
||||||
# Output of 'npm pack'
|
# Output of 'npm pack'
|
||||||
*.tgz
|
*.tgz
|
||||||
|
|
||||||
# Yarn Integrity file
|
# Yarn Integrity file
|
||||||
.yarn-integrity
|
.yarn-integrity
|
||||||
|
|
||||||
# dotenv environment variables file
|
# dotenv environment variables file
|
||||||
.env
|
.env
|
||||||
.env.test
|
.env.test
|
||||||
|
|
||||||
# parcel-bundler cache (https://parceljs.org/)
|
# parcel-bundler cache (https://parceljs.org/)
|
||||||
.cache
|
.cache
|
||||||
|
|
||||||
# Next.js build output
|
# Next.js build output
|
||||||
.next
|
.next
|
||||||
|
|
||||||
# Nuxt.js build / generate output
|
# Nuxt.js build / generate output
|
||||||
.nuxt
|
.nuxt
|
||||||
dist
|
dist
|
||||||
|
|
||||||
# Gatsby files
|
# Gatsby files
|
||||||
.cache/
|
.cache/
|
||||||
# Comment in the public line in if your project uses Gatsby and *not* Next.js
|
# Comment in the public line in if your project uses Gatsby and *not* Next.js
|
||||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||||
# public
|
# public
|
||||||
|
|
||||||
# vuepress build output
|
# vuepress build output
|
||||||
.vuepress/dist
|
.vuepress/dist
|
||||||
|
|
||||||
# Serverless directories
|
# Serverless directories
|
||||||
.serverless/
|
.serverless/
|
||||||
|
|
||||||
# FuseBox cache
|
# FuseBox cache
|
||||||
.fusebox/
|
.fusebox/
|
||||||
|
|
||||||
# DynamoDB Local files
|
# DynamoDB Local files
|
||||||
.dynamodb/
|
.dynamodb/
|
||||||
|
|
||||||
# TernJS port file
|
# TernJS port file
|
||||||
.tern-port
|
.tern-port
|
||||||
|
|
||||||
# Output files
|
# Output files
|
||||||
public/*.html
|
public/*.html
|
||||||
public/*.js
|
public/*.js
|
||||||
public/*.css
|
public/*.css
|
||||||
public/*.map
|
public/*.map
|
||||||
public/*.gz
|
public/*.gz
|
||||||
|
public/*.txt
|
||||||
letsencrypt/
|
|
||||||
mysql/
|
letsencrypt/
|
||||||
Dockerfile
|
mysql/
|
||||||
docker-compose.yml
|
Dockerfile
|
||||||
startup.sql
|
docker-compose.yml
|
||||||
|
startup.sql
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
Copyright (c) 2021 Kayne Ruse, KR Game Studios
|
Copyright (c) 2021-2023 Kayne Ruse, KR Game Studios
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
|
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
# MERN-template
|
# MERN-template
|
||||||
|
|
||||||
A website template using the MERN stack. The primary technology involved is:
|
A website template using the MERN stack. It is geared towards Persistent Browser Based Games (think neopets), but is flexible enough for a number of different uses.
|
||||||
|
|
||||||
|
The primary technology involved is:
|
||||||
|
|
||||||
* React
|
* React
|
||||||
* Nodejs
|
* Nodejs
|
||||||
* MariaDB (with Sequelize)
|
* MariaDB (with Sequelize)
|
||||||
* Docker (with docker-compose)
|
* Docker (with docker compose)
|
||||||
|
|
||||||
This template is designed to support the development of persistent browser based games (PBBGs), but it, and it's component microservices, can be used elsewhere.
|
This template is designed to support the development of persistent browser based games (PBBGs), but it, and it's component microservices, can be used elsewhere.
|
||||||
|
|
||||||
@@ -27,8 +29,9 @@ A clean install is this easy:
|
|||||||
|
|
||||||
```
|
```
|
||||||
git clone https://github.com/krgamestudios/MERN-template.git
|
git clone https://github.com/krgamestudios/MERN-template.git
|
||||||
|
cd MERN-template
|
||||||
node configure-script.js
|
node configure-script.js
|
||||||
docker-compose up --build
|
docker compose up --build
|
||||||
```
|
```
|
||||||
|
|
||||||
# Setup Development
|
# Setup Development
|
||||||
@@ -36,11 +39,12 @@ docker-compose up --build
|
|||||||
To set up this template in development mode:
|
To set up this template in development mode:
|
||||||
|
|
||||||
1. Ensure mariadb is running in your development environment
|
1. Ensure mariadb is running in your development environment
|
||||||
2. Run `mariadb sql/create_database.sql` as the root user
|
2. Run `mariadb tools/create_database.sql` as the root user
|
||||||
3. Run `npm install`
|
3. Run `npm install`
|
||||||
4. Run `cp .envdev .env` and enter your details into the `.env` file
|
4. Run `cp .envdev .env` and enter your details into the `.env` file
|
||||||
5. Execute `npm run dev`
|
5. Execute `npm run dev`
|
||||||
6. Navigate to `http://localhost:3001` in your web browser
|
6. Navigate to `http://localhost:3001` in your web browser
|
||||||
|
7. Repeat this process for each microservice (linked above)
|
||||||
|
|
||||||
# Features List
|
# Features List
|
||||||
|
|
||||||
@@ -53,6 +57,8 @@ To set up this template in development mode:
|
|||||||
- Account deletion
|
- Account deletion
|
||||||
- Password management
|
- Password management
|
||||||
- JSON web token authentication
|
- JSON web token authentication
|
||||||
|
- HttpOnly cookies for security
|
||||||
|
- Optional post validation hook
|
||||||
- Fully Featured News Blog (as a microservice)
|
- Fully Featured News Blog (as a microservice)
|
||||||
- Publish, edit or delete articles as needed
|
- Publish, edit or delete articles as needed
|
||||||
- Secured via admin panel
|
- Secured via admin panel
|
||||||
@@ -72,6 +78,8 @@ To set up this template in development mode:
|
|||||||
|
|
||||||
- Full documentation
|
- Full documentation
|
||||||
- Modding tutorials
|
- Modding tutorials
|
||||||
|
- Fully Featured News Blog (as a microservice)
|
||||||
|
- Individual pages for news articles
|
||||||
|
|
||||||
# Coming Eventually
|
# Coming Eventually
|
||||||
|
|
||||||
@@ -83,7 +91,6 @@ To set up this template in development mode:
|
|||||||
- Private messaging
|
- Private messaging
|
||||||
- Broadcasting to all channels
|
- Broadcasting to all channels
|
||||||
- Badges next to usernames
|
- Badges next to usernames
|
||||||
- Better compression for client files
|
|
||||||
- Backend for leaderboards (modding tutorial?)
|
- Backend for leaderboards (modding tutorial?)
|
||||||
- Backend for energy systems (modding tutorial?)
|
- Backend for energy systems (modding tutorial?)
|
||||||
- Backend for items, shops, trading and currency
|
- Backend for items, shops, trading and currency (modding tutorial?)
|
||||||
|
|||||||
+11
-12
@@ -1,15 +1,14 @@
|
|||||||
//polyfills
|
|
||||||
import 'regenerator-runtime/runtime';
|
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom/client';
|
||||||
|
|
||||||
import App from './components/app';
|
import App from './pages/app';
|
||||||
import TokenProvider from './components/utilities/token-provider';
|
import TokenProvider from './pages/utilities/token-provider';
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM
|
||||||
<TokenProvider>
|
.createRoot(document.getElementById('root'))
|
||||||
<App />
|
.render(
|
||||||
</TokenProvider>,
|
<TokenProvider>
|
||||||
document.querySelector('#root')
|
<App />
|
||||||
);
|
</TokenProvider>
|
||||||
|
)
|
||||||
|
;
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
//react
|
|
||||||
import React, { useContext } from 'react';
|
|
||||||
import { BrowserRouter, Switch } from 'react-router-dom';
|
|
||||||
import { TokenContext } from './utilities/token-provider';
|
|
||||||
|
|
||||||
//library components
|
|
||||||
import LazyRoute from './utilities/lazy-route';
|
|
||||||
import Markdown from './panels/markdown';
|
|
||||||
|
|
||||||
//styling
|
|
||||||
//import a styling template here
|
|
||||||
|
|
||||||
//common components
|
|
||||||
import Header from './panels/header';
|
|
||||||
import Footer from './panels/footer';
|
|
||||||
import PopupChat from './panels/popup-chat';
|
|
||||||
|
|
||||||
const App = props => {
|
|
||||||
const authTokens = useContext(TokenContext);
|
|
||||||
|
|
||||||
//default render
|
|
||||||
return (
|
|
||||||
<BrowserRouter>
|
|
||||||
<Header />
|
|
||||||
<Switch>
|
|
||||||
<LazyRoute exact path='/' component={() => import('./pages/homepage')} />
|
|
||||||
|
|
||||||
<LazyRoute path='/signup' component={() => import('./pages/signup')} />
|
|
||||||
<LazyRoute path='/login' component={() => import('./pages/login')} />
|
|
||||||
<LazyRoute path='/account' component={() => import('./pages/account')} />
|
|
||||||
|
|
||||||
<LazyRoute path='/admin' component={() => import('./pages/admin')} />
|
|
||||||
<LazyRoute path='/mod' component={() => import('./pages/mod')} />
|
|
||||||
|
|
||||||
<LazyRoute path='/privacypolicy' component={async () => () => <Markdown content={require('../markdown/privacy-policy.md').default} />} />
|
|
||||||
<LazyRoute path='/credits' component={async () => () => <Markdown content={require('../markdown/credits.md').default} />} />
|
|
||||||
|
|
||||||
<LazyRoute path='*' component={() => import('./pages/not-found')} />
|
|
||||||
</Switch>
|
|
||||||
{ authTokens.accessToken ? <PopupChat /> : <></> }
|
|
||||||
<Footer />
|
|
||||||
</BrowserRouter>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default App;
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
import React, { useEffect, useContext, useRef } from 'react';
|
|
||||||
import { Redirect } from 'react-router-dom';
|
|
||||||
|
|
||||||
import { TokenContext } from '../utilities/token-provider';
|
|
||||||
|
|
||||||
import DeleteAccount from '../panels/delete-account';
|
|
||||||
|
|
||||||
const Account = props => {
|
|
||||||
//context
|
|
||||||
const authTokens = useContext(TokenContext);
|
|
||||||
|
|
||||||
//misplaced?
|
|
||||||
if (!authTokens.accessToken) {
|
|
||||||
return <Redirect to='/' />;
|
|
||||||
}
|
|
||||||
|
|
||||||
//refs
|
|
||||||
const passwordRef = useRef();
|
|
||||||
const retypeRef = useRef();
|
|
||||||
const contactRef = useRef();
|
|
||||||
|
|
||||||
//grab the user's info
|
|
||||||
useEffect(() => {
|
|
||||||
authTokens.tokenFetch(`${process.env.AUTH_URI}/auth/account`, {
|
|
||||||
method: 'GET',
|
|
||||||
headers: {
|
|
||||||
'Access-Control-Allow-Origin': '*'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(blob => blob.json())
|
|
||||||
.then(json => contactRef.current.checked = json.contact)
|
|
||||||
.catch(e => console.error(e))
|
|
||||||
;
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
//render the thing
|
|
||||||
return (
|
|
||||||
<div className='page'>
|
|
||||||
<h1 className='centered'>Account</h1>
|
|
||||||
<form className='constricted' onSubmit={async evt => {
|
|
||||||
evt.preventDefault();
|
|
||||||
const [err] = await update(passwordRef.current.value, retypeRef.current.value, contactRef.current.checked, authTokens.tokenFetch);
|
|
||||||
|
|
||||||
if (err) {
|
|
||||||
alert(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
alert('Details updated');
|
|
||||||
passwordRef.current.value = retypeRef.current.value = '';
|
|
||||||
}}>
|
|
||||||
<div>
|
|
||||||
<div>
|
|
||||||
<label htmlFor='password'>Change Password:</label>
|
|
||||||
<input type='password' name='password' ref={passwordRef} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label htmlFor='retype'>Retype Password:</label>
|
|
||||||
<input type='password' name='retype' ref={retypeRef} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label htmlFor='contact'>Allow Promotional Emails:</label>
|
|
||||||
<input type='checkbox' name='contact' ref={contactRef} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type='submit'>Update Information</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<DeleteAccount className='constricted' />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const update = async (password, retype, contact, tokenFetch) => {
|
|
||||||
if (password != retype) {
|
|
||||||
return ['Passwords do not match'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (password && password.length < 8) {
|
|
||||||
return ['Password is too short'];
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await tokenFetch(`${process.env.AUTH_URI}/auth/account`, {
|
|
||||||
method: 'PATCH',
|
|
||||||
headers: {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
password: password ? password : null,
|
|
||||||
contact
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!result.ok) {
|
|
||||||
return [`${await result.status}: ${await result.text()}`];
|
|
||||||
} else {
|
|
||||||
return [null];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Account;
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
import React, { useContext } from 'react';
|
|
||||||
import { Redirect } from 'react-router-dom';
|
|
||||||
|
|
||||||
import { TokenContext } from '../utilities/token-provider';
|
|
||||||
|
|
||||||
import NewsPublisher from '../panels/news-publisher';
|
|
||||||
import NewsEditor from '../panels/news-editor';
|
|
||||||
|
|
||||||
import GrantAdmin from '../panels/grant-admin';
|
|
||||||
import GrantMod from '../panels/grant-mod';
|
|
||||||
|
|
||||||
const Admin = props => {
|
|
||||||
//context
|
|
||||||
const authTokens = useContext(TokenContext);
|
|
||||||
|
|
||||||
//misplaced? (admin only)
|
|
||||||
if (!authTokens.accessToken || !authTokens.getPayload().admin) {
|
|
||||||
return <Redirect to='/' />;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className='page'>
|
|
||||||
<h1 className='centered'>Administration Tools</h1>
|
|
||||||
<NewsPublisher />
|
|
||||||
<NewsEditor />
|
|
||||||
<GrantAdmin />
|
|
||||||
<GrantMod />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Admin;
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
|
|
||||||
import NewsFeed from '../panels/news-feed';
|
|
||||||
|
|
||||||
const HomePage = props => {
|
|
||||||
return (
|
|
||||||
<div className='page'>
|
|
||||||
<p>This is the MERN template homepage.</p>
|
|
||||||
<NewsFeed />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default HomePage;
|
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
import React, { useContext, useRef } from 'react';
|
|
||||||
import { Redirect } from 'react-router-dom';
|
|
||||||
|
|
||||||
import { TokenContext } from '../utilities/token-provider';
|
|
||||||
|
|
||||||
const validateEmail = require('../../../common/utilities/validate-email');
|
|
||||||
|
|
||||||
const LogIn = props => {
|
|
||||||
//context
|
|
||||||
const authTokens = useContext(TokenContext);
|
|
||||||
|
|
||||||
//misplaced?
|
|
||||||
if (authTokens.accessToken) {
|
|
||||||
return <Redirect to='/' />;
|
|
||||||
}
|
|
||||||
|
|
||||||
//refs
|
|
||||||
const emailRef = useRef();
|
|
||||||
const passwordRef = useRef();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className='page'>
|
|
||||||
<h1 className='centered'>Login</h1>
|
|
||||||
<form className='constricted' onSubmit={
|
|
||||||
async evt => {
|
|
||||||
//on submit
|
|
||||||
evt.preventDefault();
|
|
||||||
const [err, newTokens] = await handleSubmit(emailRef.current.value, passwordRef.current.value);
|
|
||||||
if (err) {
|
|
||||||
alert(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
//save auth tokens and redirect
|
|
||||||
if (newTokens) {
|
|
||||||
authTokens.setAccessToken(newTokens.accessToken);
|
|
||||||
authTokens.setRefreshToken(newTokens.refreshToken);
|
|
||||||
|
|
||||||
props.history.push('/');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}>
|
|
||||||
<div>
|
|
||||||
<label htmlFor="email">Email:</label>
|
|
||||||
<input type="email" name="email" ref={emailRef} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label htmlFor="password">Password:</label>
|
|
||||||
<input type="password" name="password" ref={passwordRef} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type='submit'>Login</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
//DOCS: returns two values: err and authTokens
|
|
||||||
const handleSubmit = async (email, password) => {
|
|
||||||
email = email.trim();
|
|
||||||
|
|
||||||
const err = handleValidation(email, password);
|
|
||||||
|
|
||||||
if (err) {
|
|
||||||
return [err, false];
|
|
||||||
}
|
|
||||||
|
|
||||||
//send to the auth server
|
|
||||||
const result = await fetch(`${process.env.AUTH_URI}/auth/login`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Access-Control-Allow-Origin': '*'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
email,
|
|
||||||
password,
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
//handle errors
|
|
||||||
if (!result.ok) {
|
|
||||||
const err = `${result.status}: ${await result.text()}`;
|
|
||||||
console.error(err);
|
|
||||||
return [err, false];
|
|
||||||
}
|
|
||||||
|
|
||||||
//return the new auth tokens
|
|
||||||
const newTokens = await result.json();
|
|
||||||
return [null, newTokens];
|
|
||||||
};
|
|
||||||
|
|
||||||
//returns an error message, or null on success
|
|
||||||
const handleValidation = (email, password) => {
|
|
||||||
if (!validateEmail(email)) {
|
|
||||||
return 'invalid email';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (password.length < 8) {
|
|
||||||
return 'invalid password (Must be at least 8 characters long)';
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
export default LogIn;
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
import React, { useContext } from 'react';
|
|
||||||
import { Redirect } from 'react-router-dom';
|
|
||||||
|
|
||||||
import { TokenContext } from '../utilities/token-provider';
|
|
||||||
|
|
||||||
import ChatReports from '../panels/chat-reports';
|
|
||||||
import BanUser from '../panels/ban-user';
|
|
||||||
|
|
||||||
const Mod = props => {
|
|
||||||
//context
|
|
||||||
const authTokens = useContext(TokenContext);
|
|
||||||
|
|
||||||
//misplaced? (admin only)
|
|
||||||
if (!authTokens.accessToken || !(authTokens.getPayload().admin || authTokens.getPayload().mod)) {
|
|
||||||
return <Redirect to='/' />;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className='page'>
|
|
||||||
<h1 className='centered'>Moderation Tools</h1>
|
|
||||||
<ChatReports />
|
|
||||||
<BanUser />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Mod;
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
|
|
||||||
const NotFound = props => {
|
|
||||||
return (
|
|
||||||
<div className='page'>
|
|
||||||
<h1 className='middle centered'>Page Not Found</h1>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default NotFound;
|
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
import React, { useContext, useRef } from 'react';
|
|
||||||
import { Redirect } from 'react-router-dom';
|
|
||||||
|
|
||||||
import { TokenContext } from '../utilities/token-provider';
|
|
||||||
|
|
||||||
//utilities
|
|
||||||
const validateEmail = require('../../../common/utilities/validate-email');
|
|
||||||
const validateUsername = require('../../../common/utilities/validate-username');
|
|
||||||
|
|
||||||
const SignUp = props => {
|
|
||||||
//context
|
|
||||||
const authTokens = useContext(TokenContext);
|
|
||||||
|
|
||||||
//misplaced?
|
|
||||||
if (authTokens.accessToken) {
|
|
||||||
return <Redirect to='/' />;
|
|
||||||
}
|
|
||||||
|
|
||||||
//refs
|
|
||||||
const emailRef = useRef();
|
|
||||||
const usernameRef = useRef();
|
|
||||||
const passwordRef = useRef();
|
|
||||||
const retypeRef = useRef();
|
|
||||||
const contactRef = useRef();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className='page'>
|
|
||||||
<h1 className='centered'>Signup</h1>
|
|
||||||
<form className='constricted' onSubmit={
|
|
||||||
async evt => { //on submit
|
|
||||||
evt.preventDefault();
|
|
||||||
const [result, redirect] = await handleSubmit(emailRef.current.value, usernameRef.current.value, passwordRef.current.value, retypeRef.current.value, contactRef.current.checked);
|
|
||||||
if (result) {
|
|
||||||
alert(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
//redirect
|
|
||||||
if (redirect) {
|
|
||||||
props.history.push('/');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}>
|
|
||||||
<div>
|
|
||||||
<label htmlFor='email'>Email:</label>
|
|
||||||
<input type='email' name='email' ref={emailRef} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label htmlFor='username'>Username:</label>
|
|
||||||
<input type='text' name='username' ref={usernameRef} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label htmlFor='password'>Password:</label>
|
|
||||||
<input type='password' name='password' ref={passwordRef} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label htmlFor='retype'>Retype Password:</label>
|
|
||||||
<input type='password' name='retype' ref={retypeRef} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label htmlFor='contact'>Allow Promotional Emails:</label>
|
|
||||||
<input type='checkbox' name='contact' ref={contactRef} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type='submit'>Signup</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSubmit = async (email, username, password, retype, contact) => {
|
|
||||||
email = email.trim();
|
|
||||||
username = username.trim();
|
|
||||||
|
|
||||||
const err = handleValidation(email, username, password, retype);
|
|
||||||
|
|
||||||
if (err) {
|
|
||||||
return [err];
|
|
||||||
}
|
|
||||||
|
|
||||||
//send to the auth server
|
|
||||||
const result = await fetch(`${process.env.AUTH_URI}/auth/signup`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Access-Control-Allow-Origin': '*'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
email,
|
|
||||||
username,
|
|
||||||
password,
|
|
||||||
contact
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!result.ok) {
|
|
||||||
const err = `${result.status}: ${await result.text()}`;
|
|
||||||
console.error(err);
|
|
||||||
return [err, false];
|
|
||||||
}
|
|
||||||
|
|
||||||
return [await result.text(), true];
|
|
||||||
};
|
|
||||||
|
|
||||||
//returns an error message, or null on success
|
|
||||||
const handleValidation = (email, username, password, retype) => {
|
|
||||||
if (!validateEmail(email)) {
|
|
||||||
return 'invalid email';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!validateUsername(username)) {
|
|
||||||
return 'invalid username';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (password.length < 8) {
|
|
||||||
return 'invalid password (Must be at least 8 characters long)';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (password !== retype) {
|
|
||||||
return 'passwords do not match';
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default SignUp;
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
import React, { useState, useEffect, useContext } from 'react';
|
|
||||||
import { TokenContext } from '../utilities/token-provider';
|
|
||||||
import dateFormat from 'dateformat';
|
|
||||||
|
|
||||||
const ChatReports = props => {
|
|
||||||
const [reports, setReports] = useState([]);
|
|
||||||
|
|
||||||
const authTokens = useContext(TokenContext);
|
|
||||||
|
|
||||||
useEffect(async () => {
|
|
||||||
const result = await authTokens.tokenFetch(`${process.env.CHAT_URI}/admin/reports`, {
|
|
||||||
method: 'GET',
|
|
||||||
headers: {
|
|
||||||
'Access-Control-Allow-Origin': '*'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!result.ok) {
|
|
||||||
const err = `${result.status}: ${await result.text()}`;
|
|
||||||
console.log(err);
|
|
||||||
alert(err);
|
|
||||||
} else {
|
|
||||||
setReports(await result.json());
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Date</th>
|
|
||||||
<th>Username</th>
|
|
||||||
<th>Room Name</th>
|
|
||||||
<th>Content</th>
|
|
||||||
<th>Reported By</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{reports.map((report, index) => (
|
|
||||||
<tr key={index}>
|
|
||||||
<td>{dateFormat(report.chatlog.createdAt, 'yyyy-mm-dd, H:MM:ss')}</td>
|
|
||||||
<td>{report.chatlog.username}</td>
|
|
||||||
<td>{report.chatlog.room}</td>
|
|
||||||
<td>{report.chatlog.text}</td>
|
|
||||||
<td>{report.reporter.join(', ')}</td>
|
|
||||||
<td><button onClick={() => deleteReportsFor(report.chatlogId, authTokens.tokenFetch, setReports)}>Delete</button></td>
|
|
||||||
</tr>
|
|
||||||
))}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const deleteReportsFor = (chatlogId, tokenFetch, setReports) => {
|
|
||||||
tokenFetch(`${process.env.CHAT_URI}/admin/reports`, {
|
|
||||||
method: 'DELETE',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Access-Control-Allow-Origin': '*'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ chatlogId })
|
|
||||||
});
|
|
||||||
|
|
||||||
setReports(reports => reports.filter(report => report.chatlogId != chatlogId));
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ChatReports;
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { Link } from 'react-router-dom';
|
|
||||||
|
|
||||||
const Footer = () => {
|
|
||||||
return (
|
|
||||||
<footer>
|
|
||||||
<p className='centered'>MERN template designed by <a href='https://krgamestudios.com'>Kayne Ruse, KR Game Studios</a> - <Link to='/privacypolicy'>Privacy Policy</Link> - <Link to='/credits'>Credits</Link></p>
|
|
||||||
</footer>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Footer;
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
import React, { useContext } from 'react';
|
|
||||||
import { Link } from 'react-router-dom';
|
|
||||||
|
|
||||||
import { TokenContext } from '../utilities/token-provider';
|
|
||||||
|
|
||||||
const Visitor = () => {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<Link to='/signup'>Sign Up</Link>
|
|
||||||
<span> - </span>
|
|
||||||
<Link to='/login'>Log In</Link>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const Member = () => {
|
|
||||||
const authTokens = useContext(TokenContext);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<Link to='/account'>Account</Link>
|
|
||||||
<span> - </span>
|
|
||||||
|
|
||||||
{ authTokens.getPayload().admin ?
|
|
||||||
<span>
|
|
||||||
<Link to='/admin'>Admin</Link>
|
|
||||||
<span> - </span>
|
|
||||||
</span>:
|
|
||||||
<span />
|
|
||||||
}
|
|
||||||
|
|
||||||
{ authTokens.getPayload().mod ?
|
|
||||||
<span>
|
|
||||||
<Link to='/mod'>Moderation</Link>
|
|
||||||
<span> - </span>
|
|
||||||
</span>:
|
|
||||||
<span />
|
|
||||||
}
|
|
||||||
|
|
||||||
{ /* Logout button logs you out of the server too */ }
|
|
||||||
<Link to='/' onClick={async () => {
|
|
||||||
const result = await authTokens.tokenFetch(`${process.env.AUTH_URI}/auth/logout`, { //NOTE: this gets overwritten as a bugfix
|
|
||||||
method: 'DELETE',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Access-Control-Allow-Origin': '*'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
token: authTokens.refreshToken
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
//any problems?
|
|
||||||
if (!result.ok) {
|
|
||||||
console.error(await result.text());
|
|
||||||
} else {
|
|
||||||
authTokens.setAccessToken('');
|
|
||||||
authTokens.setRefreshToken('');
|
|
||||||
}
|
|
||||||
}}>Log out</Link>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const Header = () => {
|
|
||||||
const authTokens = useContext(TokenContext);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<header>
|
|
||||||
<h1><Link to='/'>MERN Template</Link></h1>
|
|
||||||
{ authTokens.accessToken ? <Member /> : <Visitor /> }
|
|
||||||
</header>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Header;
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
|
||||||
import ReactMarkdown from 'react-markdown';
|
|
||||||
import rehypeRaw from 'rehype-raw';
|
|
||||||
|
|
||||||
const Markdown = props => {
|
|
||||||
//content?
|
|
||||||
let [contentHook, setContentHook] = useState(null);
|
|
||||||
|
|
||||||
//check arguments
|
|
||||||
if (!props.content) {
|
|
||||||
if (!props.uri) {
|
|
||||||
throw 'Markdown requires either content or uri prop';
|
|
||||||
}
|
|
||||||
|
|
||||||
//once
|
|
||||||
useEffect(() => {
|
|
||||||
fetch(props.uri)
|
|
||||||
.then(blob => blob.text())
|
|
||||||
.then(blob => setContentHook(blob))
|
|
||||||
.catch(e => console.error(e))
|
|
||||||
;
|
|
||||||
}, []);
|
|
||||||
} else
|
|
||||||
|
|
||||||
//assume raw info
|
|
||||||
if (!contentHook) {
|
|
||||||
setContentHook(props.content);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ReactMarkdown rehypePlugins={[rehypeRaw]} escapeHtml={false} props={{...props}}>{contentHook}</ReactMarkdown>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Markdown;
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { Route } from 'react-router-dom';
|
|
||||||
import loadable from '@loadable/component';
|
|
||||||
|
|
||||||
const LazyRoute = props => {
|
|
||||||
const { component, ...lazyProps } = props;
|
|
||||||
|
|
||||||
const lazyComponent = loadable(component);
|
|
||||||
|
|
||||||
return <Route {...lazyProps} component={lazyComponent} />
|
|
||||||
};
|
|
||||||
|
|
||||||
export default LazyRoute;
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
# Credits
|
|
||||||
|
|
||||||
MERN Template developed by Kayne Ruse, KR Game Studios
|
|
||||||
|
|
||||||
[https://github.com/krgamestudios/MERN-template](https://github.com/krgamestudios/MERN-template)
|
|
||||||
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
# Privacy Policy
|
|
||||||
|
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
import React, { useEffect, useContext, useRef } from 'react';
|
||||||
|
import { Link, Navigate } from 'react-router';
|
||||||
|
|
||||||
|
import ApplyToBody from '../utilities/apply-to-body';
|
||||||
|
|
||||||
|
import { TokenContext } from '../utilities/token-provider';
|
||||||
|
|
||||||
|
import DeleteAccount from './panels/delete-account';
|
||||||
|
|
||||||
|
const Account = props => {
|
||||||
|
//context
|
||||||
|
const authTokens = useContext(TokenContext);
|
||||||
|
|
||||||
|
//misplaced?
|
||||||
|
if (!authTokens.accessToken) {
|
||||||
|
return <Navigate to='/' />;
|
||||||
|
}
|
||||||
|
|
||||||
|
//refs
|
||||||
|
const passwordRef = useRef();
|
||||||
|
const retypeRef = useRef();
|
||||||
|
const contactRef = useRef();
|
||||||
|
|
||||||
|
//grab the user's info
|
||||||
|
useEffect(() => {
|
||||||
|
authTokens.tokenFetch(`${process.env.AUTH_URI}/auth/account`)
|
||||||
|
.then(blob => blob.json())
|
||||||
|
.then(json => contactRef.current.checked = json.contact)
|
||||||
|
.catch(e => console.error(e))
|
||||||
|
;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
//render the thing
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ApplyToBody className='dashboard' />
|
||||||
|
<div className='page'>
|
||||||
|
<div className='central panel centered middle'>
|
||||||
|
<div className='panel'>
|
||||||
|
<h1 className='text centered'>Account</h1>
|
||||||
|
<div className='panel'>
|
||||||
|
<form className='constrained' onSubmit={async evt => {
|
||||||
|
evt.preventDefault();
|
||||||
|
const [err] = await update(passwordRef.current.value, retypeRef.current.value, contactRef.current.checked, authTokens.tokenFetch);
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
alert(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
alert('Details updated');
|
||||||
|
passwordRef.current.value = retypeRef.current.value = '';
|
||||||
|
}}>
|
||||||
|
<input type='password' name='password' placeholder='New Password' ref={passwordRef} />
|
||||||
|
<input type='password' name='retype' placeholder='Retype New Password' ref={retypeRef} />
|
||||||
|
|
||||||
|
<span>
|
||||||
|
<label htmlFor='contact'>Allow Promotional Emails:</label>
|
||||||
|
<input type='checkbox' name='contact' ref={contactRef} />
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<button type='submit'>Update Information</button>
|
||||||
|
</form>
|
||||||
|
<DeleteAccount />
|
||||||
|
</div>
|
||||||
|
<Link to='/' className='text centered'>Return Home</Link>\
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const update = async (password, retype, contact, tokenFetch) => {
|
||||||
|
if (password != retype) {
|
||||||
|
return ['Passwords do not match'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (password && password.length < 8) {
|
||||||
|
return ['Password is too short'];
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await tokenFetch(`${process.env.AUTH_URI}/auth/account`, {
|
||||||
|
method: 'PATCH',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
password: password ? password : null,
|
||||||
|
contact
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result.ok) {
|
||||||
|
return [`${await result.status}: ${await result.text()}`];
|
||||||
|
} else {
|
||||||
|
return [null];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Account;
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
import React, { useContext, useRef } from 'react';
|
||||||
|
import { Link, Navigate } from 'react-router';
|
||||||
|
|
||||||
|
import ApplyToBody from '../utilities/apply-to-body';
|
||||||
|
|
||||||
|
import { TokenContext } from '../utilities/token-provider';
|
||||||
|
|
||||||
|
const validateEmail = require('../../../common/utilities/validate-email');
|
||||||
|
|
||||||
|
const Login = props => {
|
||||||
|
//context
|
||||||
|
const authTokens = useContext(TokenContext);
|
||||||
|
|
||||||
|
//misplaced?
|
||||||
|
if (authTokens.accessToken) {
|
||||||
|
return <Navigate to='/' />;
|
||||||
|
}
|
||||||
|
|
||||||
|
//refs
|
||||||
|
const emailRef = useRef();
|
||||||
|
const passwordRef = useRef();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ApplyToBody className='dashboard' />
|
||||||
|
<div className='page'>
|
||||||
|
<div className='central panel centered middle'>
|
||||||
|
<div className='panel'>
|
||||||
|
<h1 className='text centered'>Login</h1>
|
||||||
|
<form className='constrained' onSubmit={
|
||||||
|
async evt => {
|
||||||
|
//on submit
|
||||||
|
evt.preventDefault();
|
||||||
|
const [err, accessToken] = await handleSubmit(emailRef.current.value, passwordRef.current.value);
|
||||||
|
if (err) {
|
||||||
|
alert(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
//save auth tokens and redirect
|
||||||
|
if (accessToken) {
|
||||||
|
authTokens.setAccessToken(accessToken);
|
||||||
|
|
||||||
|
return <Navigate to='/' />;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}>
|
||||||
|
<input type='email' name='email' placeholder='your@email.com' ref={emailRef} />
|
||||||
|
<input type='password' name='password' placeholder='********' ref={passwordRef} />
|
||||||
|
<button type='submit'>Login</button>
|
||||||
|
</form>
|
||||||
|
<Link to='/recover' className='text centered'>Forgot Password?</Link>
|
||||||
|
<Link to='/' className='text centered'>Return Home</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
//DOCS: returns two values: err and authTokens
|
||||||
|
const handleSubmit = async (email, password) => {
|
||||||
|
email = email.trim();
|
||||||
|
|
||||||
|
const err = handleValidation(email, password);
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
return [err, false];
|
||||||
|
}
|
||||||
|
|
||||||
|
//send to the auth server
|
||||||
|
const result = await fetch(`${process.env.AUTH_URI}/auth/login`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
email,
|
||||||
|
password,
|
||||||
|
}),
|
||||||
|
credentials: 'include'
|
||||||
|
});
|
||||||
|
|
||||||
|
//handle errors
|
||||||
|
if (!result.ok) {
|
||||||
|
const err = `${result.status}: ${await result.text()}`;
|
||||||
|
console.error(err);
|
||||||
|
return [err, false];
|
||||||
|
}
|
||||||
|
|
||||||
|
//return the new auth tokens
|
||||||
|
const accessToken = await result.text();
|
||||||
|
return [null, accessToken];
|
||||||
|
};
|
||||||
|
|
||||||
|
//returns an error message, or null on success
|
||||||
|
const handleValidation = (email, password) => {
|
||||||
|
if (!validateEmail(email)) {
|
||||||
|
return 'invalid email';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (password.length < 8) {
|
||||||
|
return 'invalid password (Must be at least 8 characters long)';
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export default Login;
|
||||||
+19
-26
@@ -1,6 +1,6 @@
|
|||||||
import React, { useState, useContext, useRef } from 'react';
|
import React, { useState, useContext, useRef } from 'react';
|
||||||
|
|
||||||
import { TokenContext } from '../utilities/token-provider';
|
import { TokenContext } from '../../utilities/token-provider';
|
||||||
|
|
||||||
//DOCS: isolated the delete account button into it's own panel, so it can be easily moved as needed
|
//DOCS: isolated the delete account button into it's own panel, so it can be easily moved as needed
|
||||||
const DeleteAccount = props => {
|
const DeleteAccount = props => {
|
||||||
@@ -9,25 +9,27 @@ const DeleteAccount = props => {
|
|||||||
const passwordRef = useRef();
|
const passwordRef = useRef();
|
||||||
|
|
||||||
if (!open) {
|
if (!open) {
|
||||||
return <button onClick={() => setOpen(true)} className={props.className}>Delete Account</button>
|
return (
|
||||||
|
<button onClick={() => setOpen(true)}>Delete Account</button>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form className={props.className} onSubmit={async evt => {
|
<div className='panel centered middle'>
|
||||||
evt.preventDefault();
|
<h2 className='text centered'>Delete Your Account?</h2>
|
||||||
const [err] = await handleSubmit(passwordRef.current.value, authTokens);
|
<form className='constrained' onSubmit={async evt => {
|
||||||
if (err) {
|
evt.preventDefault();
|
||||||
alert(err);
|
const [err] = await handleSubmit(passwordRef.current.value, authTokens);
|
||||||
}
|
if (err) {
|
||||||
}}>
|
alert(err);
|
||||||
<div>
|
}
|
||||||
<label htmlFor="password">Password:</label>
|
}}>
|
||||||
<input type="password" name="password" ref={passwordRef} />
|
<input type="password" name="password" placeholder='Password' ref={passwordRef} />
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type='submit'>Delete Account</button>
|
<button type='submit' style={{backgroundColor: 'red'}}>Delete Account</button>
|
||||||
<button type='cancel' onClick={() => { passwordRef.current.value = ''; setOpen(false); }}>Cancel</button>
|
<button type='cancel' onClick={() => { passwordRef.current.value = ''; setOpen(false); }}>Cancel</button>
|
||||||
</form>
|
</form>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -36,7 +38,6 @@ const handleSubmit = async (password, authTokens) => {
|
|||||||
const result = await authTokens.tokenFetch(`${process.env.AUTH_URI}/auth/account`, {
|
const result = await authTokens.tokenFetch(`${process.env.AUTH_URI}/auth/account`, {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
headers: {
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
@@ -50,14 +51,7 @@ const handleSubmit = async (password, authTokens) => {
|
|||||||
|
|
||||||
//force a logout
|
//force a logout
|
||||||
const result2 = await authTokens.tokenFetch(`${process.env.AUTH_URI}/auth/logout`, {
|
const result2 = await authTokens.tokenFetch(`${process.env.AUTH_URI}/auth/logout`, {
|
||||||
method: 'DELETE',
|
method: 'DELETE'
|
||||||
headers: {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
token: authTokens.refreshToken
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!result2.ok) {
|
if (!result2.ok) {
|
||||||
@@ -65,7 +59,6 @@ const handleSubmit = async (password, authTokens) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
authTokens.setAccessToken('');
|
authTokens.setAccessToken('');
|
||||||
authTokens.setRefreshToken('');
|
|
||||||
|
|
||||||
return [null];
|
return [null];
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import React, { useContext, useRef } from 'react';
|
||||||
|
import { Link } from 'react-router';
|
||||||
|
|
||||||
|
import { TokenContext } from '../../utilities/token-provider';
|
||||||
|
|
||||||
|
//TODO: make this an ACTUAL BUTTON
|
||||||
|
const Logout = () => {
|
||||||
|
const authTokens = useContext(TokenContext);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{ /* Logout logs you out of the server too */ }
|
||||||
|
<Link to='/' onClick={async () => {
|
||||||
|
const result = await authTokens.tokenFetch(`${process.env.AUTH_URI}/auth/logout`, { //NOTE: this gets overwritten as a bugfix
|
||||||
|
method: 'DELETE'
|
||||||
|
});
|
||||||
|
|
||||||
|
//any problems?
|
||||||
|
if (!result.ok) {
|
||||||
|
console.error(await result.text());
|
||||||
|
} else {
|
||||||
|
authTokens.setAccessToken('');
|
||||||
|
}
|
||||||
|
}}>Logout</Link>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Logout;
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
import React, { useContext, useRef } from 'react';
|
||||||
|
import { Link, useNavigate } from 'react-router';
|
||||||
|
|
||||||
|
import ApplyToBody from '../utilities/apply-to-body';
|
||||||
|
|
||||||
|
import { TokenContext } from '../utilities/token-provider';
|
||||||
|
|
||||||
|
//utilities
|
||||||
|
const validateEmail = require('../../../common/utilities/validate-email');
|
||||||
|
|
||||||
|
const Recover = props => {
|
||||||
|
//history
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
//context
|
||||||
|
const authTokens = useContext(TokenContext);
|
||||||
|
|
||||||
|
//misplaced?
|
||||||
|
if (authTokens.accessToken) {
|
||||||
|
navigate("/");
|
||||||
|
}
|
||||||
|
|
||||||
|
//refs
|
||||||
|
const emailRef = useRef();
|
||||||
|
const recoverRef = useRef();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ApplyToBody className='dashboard' />
|
||||||
|
<div className='page'>
|
||||||
|
<div className='central panel centered middle'>
|
||||||
|
<h1 className='text centered'>Forgot Password</h1>
|
||||||
|
<form className='constrained' onSubmit={
|
||||||
|
async evt => { //on submit
|
||||||
|
recoverRef.current.disabled = true;
|
||||||
|
evt.preventDefault();
|
||||||
|
const [result, redirect] = await handleSubmit(emailRef.current.value);
|
||||||
|
if (result) {
|
||||||
|
alert(result);
|
||||||
|
recoverRef.current.disabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//redirect
|
||||||
|
if (redirect) {
|
||||||
|
navigate("/");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}>
|
||||||
|
<input type='email' name='email' placeholder='your@email.com' ref={emailRef} />
|
||||||
|
<button type='submit' ref={recoverRef}>Recover Password</button>
|
||||||
|
</form>
|
||||||
|
<Link to='/' className='text centered'>Return Home</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = async (email) => {
|
||||||
|
email = email.trim();
|
||||||
|
|
||||||
|
const err = handleValidation(email);
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
return [err];
|
||||||
|
}
|
||||||
|
|
||||||
|
//send to the auth server
|
||||||
|
const result = await fetch(`${process.env.AUTH_URI}/auth/recover`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
email
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result.ok) {
|
||||||
|
const err = `${result.status}: ${await result.text()}`;
|
||||||
|
console.error(err);
|
||||||
|
return [err, false];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [await result.text(), true];
|
||||||
|
};
|
||||||
|
|
||||||
|
//returns an error message, or null on success
|
||||||
|
const handleValidation = (email) => {
|
||||||
|
if (!validateEmail(email)) {
|
||||||
|
return 'invalid email';
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Recover;
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
import React, { useContext, useRef } from 'react';
|
||||||
|
import { Link, useNavigate, useSearchParams } from 'react-router';
|
||||||
|
|
||||||
|
import ApplyToBody from '../utilities/apply-to-body';
|
||||||
|
|
||||||
|
import { TokenContext } from '../utilities/token-provider';
|
||||||
|
|
||||||
|
const Reset = props => {
|
||||||
|
//params
|
||||||
|
const [params, setParams] = useSearchParams(); //the URLSearchParams API
|
||||||
|
|
||||||
|
//history
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
//context
|
||||||
|
const authTokens = useContext(TokenContext);
|
||||||
|
|
||||||
|
//misplaced?
|
||||||
|
if (authTokens.accessToken || !params.has('email') || !params.has('token')) {
|
||||||
|
navigate("/");
|
||||||
|
}
|
||||||
|
|
||||||
|
//refs
|
||||||
|
const passwordRef = useRef();
|
||||||
|
const retypeRef = useRef();
|
||||||
|
|
||||||
|
//render the thing
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ApplyToBody className='dashboard' />
|
||||||
|
<div className='page'>
|
||||||
|
<div className='central panel centered middle'>
|
||||||
|
<h1 className='text centered'>Reset Password</h1>
|
||||||
|
<form className='constrained' onSubmit={async evt => {
|
||||||
|
evt.preventDefault();
|
||||||
|
const [err, redirect] = await update(passwordRef.current.value, retypeRef.current.value, params);
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
alert(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
alert('Details updated'); //TODO: replace with a message from the auth server
|
||||||
|
|
||||||
|
//redirect
|
||||||
|
if (redirect) {
|
||||||
|
navigate("/");
|
||||||
|
}
|
||||||
|
}}>
|
||||||
|
<input type='password' name='password' placeholder='New Password' ref={passwordRef} />
|
||||||
|
<input type='password' name='retype' placeholder='Retype New Password' ref={retypeRef} />
|
||||||
|
<button type='submit'>Update Information</button>
|
||||||
|
</form>
|
||||||
|
<Link to='/' className='text centered'>Return Home</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const update = async (password, retype, params) => {
|
||||||
|
if (password != retype) {
|
||||||
|
return ['Passwords do not match'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (password && password.length < 8) {
|
||||||
|
return ['Password is too short'];
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await fetch(`${process.env.AUTH_URI}/auth/reset?email=${params.get('email')}&token=${params.get('token')}`, {
|
||||||
|
method: 'PATCH',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
password: password ? password : null,
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result.ok) {
|
||||||
|
return [`${await result.status}: ${await result.text()}`];
|
||||||
|
} else {
|
||||||
|
return [null, true];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Reset;
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
import React, { useContext, useRef } from 'react';
|
||||||
|
import { Link, useNavigate } from 'react-router';
|
||||||
|
|
||||||
|
import ApplyToBody from '../utilities/apply-to-body';
|
||||||
|
|
||||||
|
import { TokenContext } from '../utilities/token-provider';
|
||||||
|
|
||||||
|
//utilities
|
||||||
|
const validateEmail = require('../../../common/utilities/validate-email');
|
||||||
|
const validateUsername = require('../../../common/utilities/validate-username');
|
||||||
|
|
||||||
|
const Signup = props => {
|
||||||
|
//history
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
//context
|
||||||
|
const authTokens = useContext(TokenContext);
|
||||||
|
|
||||||
|
//misplaced?
|
||||||
|
if (authTokens.accessToken) {
|
||||||
|
navigate("/");
|
||||||
|
}
|
||||||
|
|
||||||
|
//refs
|
||||||
|
const emailRef = useRef();
|
||||||
|
const usernameRef = useRef();
|
||||||
|
const passwordRef = useRef();
|
||||||
|
const retypeRef = useRef();
|
||||||
|
const contactRef = useRef();
|
||||||
|
const signupRef = useRef();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ApplyToBody className='dashboard' />
|
||||||
|
<div className='page'>
|
||||||
|
<div className='central panel centered middle'>
|
||||||
|
<h1 className='text centered'>Signup</h1>
|
||||||
|
<form className='constrained' onSubmit={
|
||||||
|
async evt => { //on submit
|
||||||
|
signupRef.current.disabled = true;
|
||||||
|
evt.preventDefault();
|
||||||
|
const [result, redirect] = await handleSubmit(emailRef.current.value, usernameRef.current.value, passwordRef.current.value, retypeRef.current.value, contactRef.current.checked);
|
||||||
|
if (result) {
|
||||||
|
alert(result);
|
||||||
|
signupRef.current.disabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//redirect
|
||||||
|
if (redirect) {
|
||||||
|
navigate("/");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}>
|
||||||
|
|
||||||
|
<input type='email' name='email' placeholder='your@email.com' ref={emailRef} />
|
||||||
|
<input type='text' name='username' placeholder='Username' ref={usernameRef} />
|
||||||
|
<input type='password' name='password' placeholder='********' ref={passwordRef} />
|
||||||
|
<input type='password' name='retype' placeholder='********' ref={retypeRef} />
|
||||||
|
|
||||||
|
<span>
|
||||||
|
<label htmlFor='contact'>Allow Emails:</label>
|
||||||
|
<input type='checkbox' name='contact' ref={contactRef} defaultChecked='true' />
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<button type='submit' ref={signupRef}>Signup</button>
|
||||||
|
</form>
|
||||||
|
<Link to='/recover' className='text centered'>Forgot Password?</Link>
|
||||||
|
<Link to='/' className='text centered'>Return Home</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = async (email, username, password, retype, contact) => {
|
||||||
|
email = email.trim();
|
||||||
|
username = username.trim();
|
||||||
|
|
||||||
|
const err = handleValidation(email, username, password, retype);
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
return [err];
|
||||||
|
}
|
||||||
|
|
||||||
|
//send to the auth server
|
||||||
|
const result = await fetch(`${process.env.AUTH_URI}/auth/signup`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
email,
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
contact
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result.ok) {
|
||||||
|
const err = `${result.status}: ${await result.text()}`;
|
||||||
|
console.error(err);
|
||||||
|
return [err, false];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [await result.text(), true];
|
||||||
|
};
|
||||||
|
|
||||||
|
//returns an error message, or null on success
|
||||||
|
const handleValidation = (email, username, password, retype) => {
|
||||||
|
if (!validateEmail(email)) {
|
||||||
|
return 'invalid email';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!validateUsername(username)) {
|
||||||
|
return 'invalid username';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (password.length < 8) {
|
||||||
|
return 'invalid password (Must be at least 8 characters long)';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (password !== retype) {
|
||||||
|
return 'passwords do not match';
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Signup;
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import React, { useContext } from 'react';
|
||||||
|
import { Link, Navigate } from 'react-router';
|
||||||
|
|
||||||
|
import ApplyToBody from '../utilities/apply-to-body';
|
||||||
|
|
||||||
|
import { TokenContext } from '../utilities/token-provider';
|
||||||
|
|
||||||
|
import GrantAdmin from './panels/grant-admin';
|
||||||
|
import GrantMod from './panels/grant-mod';
|
||||||
|
|
||||||
|
const Admin = props => {
|
||||||
|
//context
|
||||||
|
const authTokens = useContext(TokenContext);
|
||||||
|
|
||||||
|
//misplaced? (admin only)
|
||||||
|
if (!authTokens.accessToken || !authTokens.getPayload().admin) {
|
||||||
|
return <Navigate to='/' />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ApplyToBody className='dashboard' />
|
||||||
|
<div className='page panel'>
|
||||||
|
<div className='central panel'>
|
||||||
|
<h1 className='text centered'>Administration Tools</h1>
|
||||||
|
<br />
|
||||||
|
<GrantAdmin />
|
||||||
|
<br />
|
||||||
|
<GrantMod />
|
||||||
|
<Link to='/' className='text centered'>Return Home</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Admin;
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import React, { useContext } from 'react';
|
||||||
|
import { Link, Navigate } from 'react-router';
|
||||||
|
|
||||||
|
import ApplyToBody from '../utilities/apply-to-body';
|
||||||
|
|
||||||
|
import { TokenContext } from '../utilities/token-provider';
|
||||||
|
|
||||||
|
import NewsPublisher from './panels/news-publisher';
|
||||||
|
import NewsEditor from './panels/news-editor';
|
||||||
|
|
||||||
|
import ChatReports from './panels/chat-reports';
|
||||||
|
import BanUser from './panels/ban-user';
|
||||||
|
|
||||||
|
const Mod = props => {
|
||||||
|
//context
|
||||||
|
const authTokens = useContext(TokenContext);
|
||||||
|
|
||||||
|
//misplaced? (admin only)
|
||||||
|
if (!authTokens.accessToken || !(authTokens.getPayload().admin || authTokens.getPayload().mod)) {
|
||||||
|
return <Navigate to='/' />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ApplyToBody className='dashboard' />
|
||||||
|
<div className='page panel'>
|
||||||
|
<div className='central panel'>
|
||||||
|
<h1 className='text centered'>Moderation Tools</h1>
|
||||||
|
<NewsPublisher />
|
||||||
|
<br />
|
||||||
|
<NewsEditor />
|
||||||
|
<br />
|
||||||
|
<BanUser />
|
||||||
|
<br />
|
||||||
|
<ChatReports />
|
||||||
|
<Link to='/' className='text centered'>Return Home</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Mod;
|
||||||
+6
-10
@@ -1,6 +1,6 @@
|
|||||||
import React, { useRef, useContext } from 'react';
|
import React, { useRef, useContext } from 'react';
|
||||||
|
|
||||||
import { TokenContext } from '../utilities/token-provider';
|
import { TokenContext } from '../../utilities/token-provider';
|
||||||
|
|
||||||
const BanUser = props => {
|
const BanUser = props => {
|
||||||
//context
|
//context
|
||||||
@@ -10,13 +10,10 @@ const BanUser = props => {
|
|||||||
const usernameRef = useRef();
|
const usernameRef = useRef();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className='panel'>
|
||||||
<h2 className='centered'>Permanently Ban User</h2>
|
<h2 className='text centered'>Permanently Ban User</h2>
|
||||||
<form>
|
<form className='constrained'>
|
||||||
<div>
|
<input type='text' name='username' placeholder='Username' ref={usernameRef} />
|
||||||
<label htmlFor='username'>Username:</label>
|
|
||||||
<input type='text' name='username' ref={usernameRef} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type='button' onClick={async evt => {
|
<button type='button' onClick={async evt => {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
@@ -45,8 +42,7 @@ const handleButtonPress = async (username, tokenFetch) => {
|
|||||||
const result = await tokenFetch(`${process.env.AUTH_URI}/admin/banuser`, {
|
const result = await tokenFetch(`${process.env.AUTH_URI}/admin/banuser`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json'
|
||||||
'Access-Control-Allow-Origin': '*'
|
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
username
|
username
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import React, { useState, useEffect, useContext } from 'react';
|
||||||
|
import { TokenContext } from '../../utilities/token-provider';
|
||||||
|
import dateFormat from 'dateformat';
|
||||||
|
|
||||||
|
const ChatReports = props => {
|
||||||
|
const [reports, setReports] = useState([]);
|
||||||
|
|
||||||
|
const authTokens = useContext(TokenContext);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
authTokens.tokenFetch(`${process.env.CHAT_URI}/admin/reports`)
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(json => {
|
||||||
|
setReports(json);
|
||||||
|
})
|
||||||
|
;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='panel' style={{minWidth: '100%'}}>
|
||||||
|
<h2 className='text centered'>Chat Reports</h2>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Date</th>
|
||||||
|
<th>Username</th>
|
||||||
|
<th className='mobile hide'>Room Name</th>
|
||||||
|
<th>Content</th>
|
||||||
|
<th>Reported By</th>
|
||||||
|
<th className='mobile hide'>Delete</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{reports.map((report, index) => (
|
||||||
|
<tr key={index}>
|
||||||
|
<td className='text centered'>{dateFormat(report.chatlog.createdAt, 'yyyy-mm-dd, H:MM:ss')}</td>
|
||||||
|
<td className='text centered'>{report.chatlog.username}</td>
|
||||||
|
<td className='text mobile hide centered'>{report.chatlog.room}</td>
|
||||||
|
<td className='text centered'>{report.chatlog.text}</td>
|
||||||
|
<td className='text centered'>{report.reporter.join(', ')}</td>
|
||||||
|
<td className='text mobile hide centered'><button onClick={() => deleteReportsFor(report.chatlogIndex, authTokens.tokenFetch, setReports)}>Delete</button></td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteReportsFor = (chatlogIndex, tokenFetch, setReports) => {
|
||||||
|
tokenFetch(`${process.env.CHAT_URI}/admin/reports`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ chatlogIndex })
|
||||||
|
});
|
||||||
|
|
||||||
|
setReports(reports => reports.filter(report => report.chatlogIndex != chatlogIndex));
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ChatReports;
|
||||||
+6
-10
@@ -1,6 +1,6 @@
|
|||||||
import React, { useRef, useContext } from 'react';
|
import React, { useRef, useContext } from 'react';
|
||||||
|
|
||||||
import { TokenContext } from '../utilities/token-provider';
|
import { TokenContext } from '../../utilities/token-provider';
|
||||||
|
|
||||||
const GrantAdmin = props => {
|
const GrantAdmin = props => {
|
||||||
//context
|
//context
|
||||||
@@ -10,13 +10,10 @@ const GrantAdmin = props => {
|
|||||||
const usernameRef = useRef();
|
const usernameRef = useRef();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className='panel'>
|
||||||
<h2 className='centered'>Grant Admin Privileges</h2>
|
<h2 className='text centered'>Grant Admin Privileges</h2>
|
||||||
<form>
|
<form className='constrained'>
|
||||||
<div>
|
<input type='text' name='username' placeholder='Username' ref={usernameRef} />
|
||||||
<label htmlFor='username'>Username:</label>
|
|
||||||
<input type='text' name='username' ref={usernameRef} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type='button' onClick={async evt => {
|
<button type='button' onClick={async evt => {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
@@ -54,8 +51,7 @@ const handleButtonPress = async (username, tokenFetch, method) => {
|
|||||||
const result = await tokenFetch(`${process.env.AUTH_URI}/admin/admin`, {
|
const result = await tokenFetch(`${process.env.AUTH_URI}/admin/admin`, {
|
||||||
method: method,
|
method: method,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json'
|
||||||
'Access-Control-Allow-Origin': '*'
|
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
username
|
username
|
||||||
+6
-10
@@ -1,6 +1,6 @@
|
|||||||
import React, { useRef, useContext } from 'react';
|
import React, { useRef, useContext } from 'react';
|
||||||
|
|
||||||
import { TokenContext } from '../utilities/token-provider';
|
import { TokenContext } from '../../utilities/token-provider';
|
||||||
|
|
||||||
const GrantMod = props => {
|
const GrantMod = props => {
|
||||||
//context
|
//context
|
||||||
@@ -10,13 +10,10 @@ const GrantMod = props => {
|
|||||||
const usernameRef = useRef();
|
const usernameRef = useRef();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className='panel'>
|
||||||
<h2 className='centered'>Grant Moderation Privileges</h2>
|
<h2 className='text centered'>Grant Moderation Privileges</h2>
|
||||||
<form>
|
<form className='constrained'>
|
||||||
<div>
|
<input type='text' name='username' placeholder='Username' ref={usernameRef} />
|
||||||
<label htmlFor='username'>Username:</label>
|
|
||||||
<input type='text' name='username' ref={usernameRef} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type='button' onClick={async evt => {
|
<button type='button' onClick={async evt => {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
@@ -54,8 +51,7 @@ const handleButtonPress = async (username, tokenFetch, method) => {
|
|||||||
const result = await tokenFetch(`${process.env.AUTH_URI}/admin/mod`, {
|
const result = await tokenFetch(`${process.env.AUTH_URI}/admin/mod`, {
|
||||||
method: method,
|
method: method,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json'
|
||||||
'Access-Control-Allow-Origin': '*'
|
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
username
|
username
|
||||||
+35
-64
@@ -1,7 +1,7 @@
|
|||||||
import React, { useState, useEffect, useContext, useRef } from 'react';
|
import React, { useState, useEffect, useContext, useRef } from 'react';
|
||||||
import Select from 'react-dropdown-select';
|
import Select from 'react-select';
|
||||||
|
|
||||||
import { TokenContext } from '../utilities/token-provider';
|
import { TokenContext } from '../../utilities/token-provider';
|
||||||
|
|
||||||
const NewsEditor = props => {
|
const NewsEditor = props => {
|
||||||
//context
|
//context
|
||||||
@@ -17,57 +17,40 @@ const NewsEditor = props => {
|
|||||||
const [index, setIndex] = useState(null);
|
const [index, setIndex] = useState(null);
|
||||||
|
|
||||||
//run once
|
//run once
|
||||||
useEffect(async () => {
|
useEffect(() => {
|
||||||
const result = await fetch(`${process.env.NEWS_URI}/news/metadata?limit=999`, {
|
fetch(`${process.env.NEWS_URI}/news/metadata?page_size=999`)
|
||||||
method: 'GET',
|
.then(res => res.json())
|
||||||
headers: {
|
.then(json => {
|
||||||
'Content-Type': 'application/json',
|
setArticles(json)
|
||||||
'Access-Control-Allow-Origin': '*'
|
})
|
||||||
},
|
;
|
||||||
});
|
|
||||||
|
|
||||||
if (!result.ok) {
|
|
||||||
const err = `${result.status}: ${await result.text()}`;
|
|
||||||
console.log(err);
|
|
||||||
alert(err);
|
|
||||||
} else {
|
|
||||||
setArticles(await result.json());
|
|
||||||
}
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className='panel'>
|
||||||
<h2 className='centered'>News Editor</h2>
|
<h2 className='text centered'>News Editor</h2>
|
||||||
<div>
|
<Select
|
||||||
<label htmlFor='article'>Article: </label>
|
options={articles.map(article => { return { label: article.title, index: article.index }; })}
|
||||||
<Select
|
onChange={async ({index}) => {
|
||||||
options={articles.map(article => { return { label: article.title, value: article.index }; })}
|
//fetch this article
|
||||||
onChange={async values => {
|
const result = await fetch(`${process.env.NEWS_URI}/news/archive/${index}`);
|
||||||
//fetch this article
|
|
||||||
const index = values[0].value;
|
|
||||||
|
|
||||||
const result = await fetch(`${process.env.NEWS_URI}/news/archive/${index}`, {
|
if (!result.ok) {
|
||||||
headers: {
|
const err = `${result.status}: ${await result.text()}`;
|
||||||
'Access-Control-Allow-Origin': '*'
|
console.log(err);
|
||||||
}
|
alert(err);
|
||||||
});
|
} else {
|
||||||
|
const article = await result.json();
|
||||||
|
titleRef.current.value = article.title;
|
||||||
|
authorRef.current.value = article.author;
|
||||||
|
bodyRef.current.value = article.body;
|
||||||
|
setIndex(index);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
placeholder='Select Article'
|
||||||
|
/>
|
||||||
|
|
||||||
if (!result.ok) {
|
<form className='constrained' onSubmit={async evt => {
|
||||||
const err = `${result.status}: ${await result.text()}`;
|
|
||||||
console.log(err);
|
|
||||||
alert(err);
|
|
||||||
} else {
|
|
||||||
const article = await result.json();
|
|
||||||
titleRef.current.value = article.title;
|
|
||||||
authorRef.current.value = article.author;
|
|
||||||
bodyRef.current.value = article.body;
|
|
||||||
setIndex(index);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<form onSubmit={async evt => {
|
|
||||||
//onSubmit
|
//onSubmit
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
const [err] = await handleSubmit(titleRef.current.value, authorRef.current.value, bodyRef.current.value, index, authTokens.tokenFetch);
|
const [err] = await handleSubmit(titleRef.current.value, authorRef.current.value, bodyRef.current.value, index, authTokens.tokenFetch);
|
||||||
@@ -78,20 +61,9 @@ const NewsEditor = props => {
|
|||||||
alert(`Edited as article index ${index}`);
|
alert(`Edited as article index ${index}`);
|
||||||
}
|
}
|
||||||
}}>
|
}}>
|
||||||
<div>
|
<input type='text' name='title' placeholder='Title' ref={titleRef} />
|
||||||
<label htmlFor='title'>Title: </label>
|
<input type='text' name='author' placeholder='Author' ref={authorRef} />
|
||||||
<input type='text' name='title' ref={titleRef} />
|
<textarea name='body' rows='10' cols='150' placeholder='Body of the article goes here...' ref={bodyRef} />
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label htmlFor='author'>Author: </label>
|
|
||||||
<input type='text' name='author' ref={authorRef} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label htmlFor='body'>Body: </label>
|
|
||||||
<textarea name='body' rows='10' cols='150' ref={bodyRef} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type='submit'>Update</button>
|
<button type='submit'>Update</button>
|
||||||
<button type='button' onClick={async evt => {
|
<button type='button' onClick={async evt => {
|
||||||
@@ -122,8 +94,7 @@ const handleSubmit = async (title, author, body, index, tokenFetch) => {
|
|||||||
const result = await tokenFetch(`${process.env.NEWS_URI}/news/${index}`, {
|
const result = await tokenFetch(`${process.env.NEWS_URI}/news/${index}`, {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json'
|
||||||
'Access-Control-Allow-Origin': '*'
|
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
title,
|
title,
|
||||||
+9
-21
@@ -1,6 +1,6 @@
|
|||||||
import React, { useContext, useRef } from 'react';
|
import React, { useContext, useRef } from 'react';
|
||||||
|
|
||||||
import { TokenContext } from '../utilities/token-provider';
|
import { TokenContext } from '../../utilities/token-provider';
|
||||||
|
|
||||||
const NewsPublisher = props => {
|
const NewsPublisher = props => {
|
||||||
//context
|
//context
|
||||||
@@ -12,33 +12,22 @@ const NewsPublisher = props => {
|
|||||||
const bodyRef = useRef();
|
const bodyRef = useRef();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className='panel'>
|
||||||
<h2 className='centered'>News Publisher</h2>
|
<h2 className='text centered'>News Publisher</h2>
|
||||||
<form onSubmit={async evt => {
|
<form className='constrained' onSubmit={async evt => {
|
||||||
//on submit
|
//on submit
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
const [err, index] = await handleSubmit(titleRef.current.value, authorRef.current.value, bodyRef.current.value, authTokens.tokenFetch);
|
const [err, index] = await handleSubmit(titleRef.current.value, authorRef.current.value, bodyRef.current.value, authTokens.tokenFetch);
|
||||||
if (err) {
|
if (err) {
|
||||||
alert(err);
|
alert(err);
|
||||||
} else {
|
} else {
|
||||||
titleRef.current.value = authorRef.current.value = bodyRef.current.value = '';
|
titleRef.current.value = authorRef.current.value = bodyRef.current.value = ''; //TODO: null bug here?
|
||||||
alert(`Published as article index ${index}`);
|
alert(`Published as article index ${index}`);
|
||||||
}
|
}
|
||||||
}}>
|
}}>
|
||||||
<div>
|
<input type='text' name='title' placeholder='Title' ref={titleRef} />
|
||||||
<label htmlFor='title'>Title: </label>
|
<input type='text' name='author' placeholder='Author' ref={authorRef} />
|
||||||
<input type='text' name='title' ref={titleRef} />
|
<textarea name='body' rows='10' cols='150' placeholder='Body of the article goes here...' ref={bodyRef} />
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label htmlFor='author'>Author: </label>
|
|
||||||
<input type='text' name='author' ref={authorRef} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label htmlFor='body'>Body: </label>
|
|
||||||
<textarea name='body' rows='10' cols='150' ref={bodyRef} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type='submit'>Publish</button>
|
<button type='submit'>Publish</button>
|
||||||
</form>
|
</form>
|
||||||
@@ -57,8 +46,7 @@ const handleSubmit = async (title, author, body, tokenFetch) => {
|
|||||||
{
|
{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json'
|
||||||
'Access-Control-Allow-Origin': '*'
|
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
title,
|
title,
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
//react
|
||||||
|
import React, { useContext, Suspense, lazy } from 'react';
|
||||||
|
import { BrowserRouter, Routes, Route } from 'react-router';
|
||||||
|
import { TokenContext } from './utilities/token-provider';
|
||||||
|
|
||||||
|
//styling
|
||||||
|
import '../styles/styles.css';
|
||||||
|
|
||||||
|
//common components
|
||||||
|
import Footer from './panels/footer';
|
||||||
|
import PopupChat from './panels/popup-chat';
|
||||||
|
|
||||||
|
//lazy wrappers
|
||||||
|
const Homepage = lazy(() => import('./homepage'));
|
||||||
|
const Signup = lazy(() => import('./accounts/signup'));
|
||||||
|
const Login = lazy(() => import('./accounts/login'));
|
||||||
|
const Account = lazy(() => import('./accounts/account'));
|
||||||
|
const Dashboard = lazy(() => import('./dashboard'));
|
||||||
|
const Recover = lazy(() => import('./accounts/recover'));
|
||||||
|
const Reset = lazy(() => import('./accounts/reset'));
|
||||||
|
const Admin = lazy(() => import('./administration/admin'));
|
||||||
|
const Mod = lazy(() => import('./administration/mod'));
|
||||||
|
const PrivacyPolicy = lazy(() => import('./static/privacy-policy'));
|
||||||
|
const Credits = lazy(() => import('./static/credits'));
|
||||||
|
const NotFound = lazy(() => import('./not-found'));
|
||||||
|
|
||||||
|
const App = props => {
|
||||||
|
const authTokens = useContext(TokenContext);
|
||||||
|
|
||||||
|
//default render
|
||||||
|
return (
|
||||||
|
<BrowserRouter>
|
||||||
|
<Suspense>
|
||||||
|
<Routes>
|
||||||
|
<Route exact path='/' element={<Homepage />} />
|
||||||
|
|
||||||
|
<Route path='/signup' element={<Signup />} />
|
||||||
|
<Route path='/login' element={<Login />} />
|
||||||
|
<Route path='/account' element={<Account />} />
|
||||||
|
<Route path='/dashboard' element={<Dashboard />} />
|
||||||
|
|
||||||
|
<Route path='/recover' element={<Recover />} />
|
||||||
|
<Route path='/reset' element={<Reset />} />
|
||||||
|
|
||||||
|
<Route path='/admin' element={<Admin />} />
|
||||||
|
<Route path='/mod' element={<Mod />} />
|
||||||
|
|
||||||
|
<Route path='/privacypolicy' element={<PrivacyPolicy />} />
|
||||||
|
<Route path='/credits' element={<Credits />} />
|
||||||
|
|
||||||
|
<Route path='*' element={<NotFound />} />
|
||||||
|
</Routes>
|
||||||
|
</Suspense>
|
||||||
|
{ authTokens.accessToken ? <PopupChat /> : <></> }
|
||||||
|
<Footer />
|
||||||
|
</BrowserRouter>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default App;
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import React, { useContext } from 'react';
|
||||||
|
import { Link, Navigate } from 'react-router';
|
||||||
|
|
||||||
|
import ApplyToBody from './utilities/apply-to-body';
|
||||||
|
|
||||||
|
import { TokenContext } from './utilities/token-provider';
|
||||||
|
|
||||||
|
import Logout from './accounts/panels/logout';
|
||||||
|
|
||||||
|
const Dashboard = props => {
|
||||||
|
//context
|
||||||
|
const authTokens = useContext(TokenContext);
|
||||||
|
|
||||||
|
//misplaced?
|
||||||
|
if (!authTokens.accessToken) {
|
||||||
|
return <Navigate to='/' />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ApplyToBody className='dashboard' />
|
||||||
|
<div className='page'>
|
||||||
|
<div className='central panel centered middle'>
|
||||||
|
<Link to='/account'>Account</Link>
|
||||||
|
{ authTokens.getPayload().admin ? <Link to='/admin' className='text centered'>Admin</Link> : <></> }
|
||||||
|
{ authTokens.getPayload().mod ? <Link to='/mod' className='text centered'>Mod</Link> : <></> }
|
||||||
|
<Logout />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Dashboard;
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import React, { useContext } from 'react';
|
||||||
|
import { Link, Navigate } from 'react-router';
|
||||||
|
|
||||||
|
import ApplyToBody from './utilities/apply-to-body';
|
||||||
|
|
||||||
|
import { TokenContext } from './utilities/token-provider';
|
||||||
|
|
||||||
|
import NewsFeed from './panels/news-feed';
|
||||||
|
|
||||||
|
const HomePage = props => {
|
||||||
|
//context
|
||||||
|
const authTokens = useContext(TokenContext);
|
||||||
|
|
||||||
|
//misplaced?
|
||||||
|
if (authTokens.accessToken) {
|
||||||
|
return <Navigate to='/dashboard' />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ApplyToBody className='homepage' />
|
||||||
|
<div className='page'>
|
||||||
|
<div className='panel above'>
|
||||||
|
<header>
|
||||||
|
<h1 className='text centered'>MERN Template</h1>
|
||||||
|
<h2 className='text centered'>This is the MERN-template</h2>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div className='panel centered middle'>
|
||||||
|
<Link to='/signup'><button>Sign Up</button></Link>
|
||||||
|
<Link to='/login'><button>Login</button></Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='panel below'>
|
||||||
|
<div className='central'>
|
||||||
|
<NewsFeed />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default HomePage;
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Link } from 'react-router';
|
||||||
|
|
||||||
|
import ApplyToBody from './utilities/apply-to-body';
|
||||||
|
|
||||||
|
const NotFound = props => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ApplyToBody className='dashboard' />
|
||||||
|
<div className='page'>
|
||||||
|
<div className='central panel centered middle'>
|
||||||
|
<h1 className='text centered'>Page Not Found</h1>
|
||||||
|
<br />
|
||||||
|
<Link className='text centered' to='/'>Return Home</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default NotFound;
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Link } from 'react-router';
|
||||||
|
|
||||||
|
const Break = () => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<span className='mobile hide'> - </span>
|
||||||
|
<br className='mobile show' />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const Footer = () => {
|
||||||
|
return (
|
||||||
|
<footer>
|
||||||
|
<p className='text centered'>© <a href='https://krgamestudios.com'>KR Game Studios</a> 2020-2024<Break /><Link to='/privacypolicy'>Privacy Policy</Link><Break /><Link to='/credits'>Credits</Link></p>
|
||||||
|
</footer>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Footer;
|
||||||
@@ -8,11 +8,6 @@ const NewsFeed = props => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
//this... um...
|
//this... um...
|
||||||
fetch(`${process.env.NEWS_URI}/news`, {
|
fetch(`${process.env.NEWS_URI}/news`, {
|
||||||
method: 'GET',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Access-Control-Allow-Origin': '*'
|
|
||||||
},
|
|
||||||
signal: aborter.current.signal //oh dear
|
signal: aborter.current.signal //oh dear
|
||||||
})
|
})
|
||||||
.then(blob => blob.json())
|
.then(blob => blob.json())
|
||||||
@@ -24,19 +19,21 @@ const NewsFeed = props => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className='panel'>
|
||||||
<h1 className='centered'>News Feed</h1>
|
<h1 className='text centered'>News Feed</h1>
|
||||||
{articles.map((article, index) => {
|
{articles.map((article, index) => {
|
||||||
return (
|
return (
|
||||||
<div key={index}>
|
<div key={index} className='panel'>
|
||||||
<hr />
|
<hr />
|
||||||
<h2>{article.title}</h2>
|
<h2>{article.title}</h2>
|
||||||
<p>Written by <strong>{article.author}</strong>, {
|
<br />
|
||||||
|
<p><em>Written by <strong>{article.author}</strong>, {
|
||||||
article.edits > 0 ?
|
article.edits > 0 ?
|
||||||
<span>Last Updated {dateFormat(article.updatedAt, 'fullDate')} ({`${article.edits} edit${article.edits > 1 ? 's': ''}`})</span> :
|
<span>Last Updated {dateFormat(article.updatedAt, 'fullDate')} ({`${article.edits} edit${article.edits > 1 ? 's': ''}`})</span> :
|
||||||
<span>Published {dateFormat(article.createdAt, 'fullDate')}</span>
|
<span>Published {dateFormat(article.createdAt, 'fullDate')}</span>
|
||||||
}</p>
|
}</em></p>
|
||||||
<p style={{whiteSpace: 'pre-wrap'}}>{article.body}</p>
|
<br />
|
||||||
|
<div dangerouslySetInnerHTML={{ __html: article.rendered }} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
@@ -4,11 +4,12 @@ import { io } from 'socket.io-client';
|
|||||||
|
|
||||||
import '../../styles/popup-chat.css';
|
import '../../styles/popup-chat.css';
|
||||||
|
|
||||||
|
//TODO: I very much need to move this out of global state
|
||||||
const socket = io(`${process.env.CHAT_URI}/chat`);
|
const socket = io(`${process.env.CHAT_URI}/chat`);
|
||||||
|
|
||||||
const PopupChat = props => {
|
const PopupChat = props => {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [chatlog, setChatlog] = useState([]);
|
const [chatlog, setChatlog] = useState([{ emphasis: true, text: 'If chat doesn\'t load, reload the page' }]);
|
||||||
|
|
||||||
const inputRef = useRef();
|
const inputRef = useRef();
|
||||||
const sendRef = useRef();
|
const sendRef = useRef();
|
||||||
@@ -77,7 +78,7 @@ const handleSend = (inputRef, pushChatlog, username, accessToken) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!inputRef.current.value.startsWith('/')) {
|
if (!inputRef.current.value.startsWith('/')) {
|
||||||
pushChatlog({ username: username, text: inputRef.current.value });
|
pushChatlog({ createdAt: (new Date(Date.now())).toISOString(), username: username, text: inputRef.current.value });
|
||||||
}
|
}
|
||||||
|
|
||||||
inputRef.current.value = '';
|
inputRef.current.value = '';
|
||||||
@@ -85,7 +86,36 @@ const handleSend = (inputRef, pushChatlog, username, accessToken) => {
|
|||||||
|
|
||||||
//render each line
|
//render each line
|
||||||
const processLine = (line, index, accessToken) => {
|
const processLine = (line, index, accessToken) => {
|
||||||
let content = <div className='content'>{line.username ? <span className='username'>{line.username}: </span> : ''}{line.text ? <span className='text'>{line.text}</span> : ''}</div>;
|
//utility functions
|
||||||
|
const isValidDate = d => {
|
||||||
|
return d instanceof Date && !isNaN(d);
|
||||||
|
};
|
||||||
|
|
||||||
|
const isToday = d => {
|
||||||
|
const now = new Date(Date.now());
|
||||||
|
return d.getDate() == now.getDate() && d.getMonth() == now.getMonth() && d.getFullYear() == now.getFullYear();
|
||||||
|
};
|
||||||
|
|
||||||
|
const isThisYear = d => {
|
||||||
|
const now = new Date(Date.now());
|
||||||
|
return d.getFullYear() == now.getFullYear();
|
||||||
|
};
|
||||||
|
|
||||||
|
//parse the date
|
||||||
|
const date = new Date(line.createdAt);
|
||||||
|
|
||||||
|
//split it up so we can format each field individually
|
||||||
|
const year = `${date.getFullYear()}`;
|
||||||
|
const month = `${date.getMonth() + 1}`;
|
||||||
|
const day = `${date.getDate()}`;
|
||||||
|
const hours = `${date.getHours()}`;
|
||||||
|
const minutes = `${date.getMinutes()}`.padStart(2, '0');
|
||||||
|
|
||||||
|
//combine into the final timestamp
|
||||||
|
const timestamp = !isValidDate(date) ? '' : isToday(date) ? `${hours}:${minutes}` : isThisYear(date) ? `${month}/${day}` : `${year}`;
|
||||||
|
|
||||||
|
//generate the content string
|
||||||
|
let content = <div className='content row'>{timestamp.length > 0 ? <span className='timestamp col'>{timestamp}</span> : null }<span className='inner col'>{line.username ? <span className='username'>{line.username}: </span> : ''}{line.text ? <span className='text'>{line.text}</span> : ''}</span></div>;
|
||||||
|
|
||||||
//decorators
|
//decorators
|
||||||
if (line.emphasis) {
|
if (line.emphasis) {
|
||||||
@@ -96,7 +126,8 @@ const processLine = (line, index, accessToken) => {
|
|||||||
content = <strong>{content}</strong>;
|
content = <strong>{content}</strong>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <li key={index} className='line'>{content}<div className='report'><a onClick={() => processReport(line, accessToken)} style={{ display: line.id && !line.notification ? 'flex' : 'none' }}>!!!</a></div></li>;
|
|
||||||
|
return <li key={index} className='line table noCollapse'>{content}<a className='report' onClick={() => processReport(line, accessToken)}>!!!</a></li>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const processReport = (line, accessToken) => {
|
const processReport = (line, accessToken) => {
|
||||||
@@ -105,7 +136,7 @@ const processReport = (line, accessToken) => {
|
|||||||
if (yes) {
|
if (yes) {
|
||||||
socket.emit('report', {
|
socket.emit('report', {
|
||||||
accessToken,
|
accessToken,
|
||||||
id: line.id
|
index: line.index
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Link } from 'react-router';
|
||||||
|
|
||||||
|
const Static = props => {
|
||||||
|
return (
|
||||||
|
<div className='page central'>
|
||||||
|
<header>
|
||||||
|
<h1 className='text centered'>Credits</h1>
|
||||||
|
</header>
|
||||||
|
<h2 className='text centered'>MERN-template</h2>
|
||||||
|
<p>The <a href='https://github.com/krgamestudios/MERN-template'>MERN-template</a> developed by Kayne Ruse, KR Game Studios</p>
|
||||||
|
|
||||||
|
<Link className='text centered' to='/'>Return Home</Link>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Static;
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Link } from 'react-router';
|
||||||
|
|
||||||
|
const Static = props => {
|
||||||
|
return (
|
||||||
|
<div className='page central'>
|
||||||
|
<header>
|
||||||
|
<h1 className="text centered">Privacy Policy</h1>
|
||||||
|
|
||||||
|
<Link className='text centered' to='/'>Return Home</Link>
|
||||||
|
</header>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Static;
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import React, { useEffect } from 'react';
|
||||||
|
|
||||||
|
//applies the classname of 'body'
|
||||||
|
const ApplyToBody = (props) => {
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
document.body.classList.add(props.className);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
document.body.classList.remove(props.className);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<></>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ApplyToBody;
|
||||||
+45
-40
@@ -1,22 +1,29 @@
|
|||||||
import React, { useState, useEffect, createContext } from 'react';
|
import React, { useState, useEffect, createContext } from 'react';
|
||||||
import decode from 'jwt-decode';
|
import { jwtDecode } from 'jwt-decode';
|
||||||
|
|
||||||
export const TokenContext = createContext();
|
export const TokenContext = createContext();
|
||||||
|
|
||||||
const TokenProvider = props => {
|
//DOCS: tokenFetch() and tokenCallback() are actually closures here
|
||||||
const [accessToken, setAccessToken] = useState('');
|
|
||||||
const [refreshToken, setRefreshToken] = useState('');
|
|
||||||
|
|
||||||
//make the access and refresh tokens persist between reloads
|
const TokenProvider = props => {
|
||||||
|
//state to be used
|
||||||
|
const [accessToken, setAccessToken] = useState('');
|
||||||
|
|
||||||
|
//force a logout under certain conditions
|
||||||
|
const forceLogout = () => {
|
||||||
|
localStorage.removeItem("accessToken");
|
||||||
|
setAccessToken("");
|
||||||
|
};
|
||||||
|
|
||||||
|
//make the access token persist between reloads
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setAccessToken(localStorage.getItem("accessToken") || '');
|
setAccessToken(localStorage.getItem("accessToken") || '');
|
||||||
setRefreshToken(localStorage.getItem("refreshToken") || '');
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
//update the stored copies
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
localStorage.setItem("accessToken", accessToken);
|
localStorage.setItem("accessToken", accessToken);
|
||||||
localStorage.setItem("refreshToken", refreshToken);
|
}, [accessToken]);
|
||||||
}, [accessToken, refreshToken]);
|
|
||||||
|
|
||||||
//wrap the default fetch function
|
//wrap the default fetch function
|
||||||
const tokenFetch = async (url, options) => {
|
const tokenFetch = async (url, options) => {
|
||||||
@@ -24,23 +31,34 @@ const TokenProvider = props => {
|
|||||||
let bearer = accessToken;
|
let bearer = accessToken;
|
||||||
|
|
||||||
//if expired (10 minutes, normally)
|
//if expired (10 minutes, normally)
|
||||||
const expired = new Date(decode(accessToken).exp * 1000) < Date.now();
|
const expired = new Date(jwtDecode(accessToken).exp) < Date.now() / 1000;
|
||||||
|
|
||||||
if (expired) {
|
if (expired) {
|
||||||
//ping the auth server for a new token
|
//BUGFIX: if logging out, just skip over the refresh token
|
||||||
|
if (url === `${process.env.AUTH_URI}/auth/logout`) {
|
||||||
|
return fetch(url, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${bearer}`
|
||||||
|
},
|
||||||
|
credentials: 'include'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//ping the auth server for a new access token
|
||||||
const response = await fetch(`${process.env.AUTH_URI}/auth/token`, {
|
const response = await fetch(`${process.env.AUTH_URI}/auth/token`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Authorization': `Bearer ${bearer}`
|
||||||
'Access-Control-Allow-Origin': '*'
|
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
credentials: 'include'
|
||||||
token: refreshToken
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//any errors, throw them
|
//any errors, throw them
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
if (response.status == 403) {
|
||||||
|
forceLogout();
|
||||||
|
}
|
||||||
throw `${response.status}: ${await response.text()}`;
|
throw `${response.status}: ${await response.text()}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,23 +66,7 @@ const TokenProvider = props => {
|
|||||||
const newAuth = await response.json();
|
const newAuth = await response.json();
|
||||||
|
|
||||||
setAccessToken(newAuth.accessToken);
|
setAccessToken(newAuth.accessToken);
|
||||||
setRefreshToken(newAuth.refreshToken);
|
|
||||||
bearer = newAuth.accessToken;
|
bearer = newAuth.accessToken;
|
||||||
|
|
||||||
//BUGFIX: logging out correctly requires the new refresh token
|
|
||||||
if (url == `${process.env.AUTH_URI}/auth/logout`) {
|
|
||||||
return fetch(`${process.env.AUTH_URI}/auth/logout`, {
|
|
||||||
method: 'DELETE',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Authorization': `Bearer ${bearer}`
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
token: newAuth.refreshToken
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//finally, delegate to fetch
|
//finally, delegate to fetch
|
||||||
@@ -73,30 +75,34 @@ const TokenProvider = props => {
|
|||||||
headers: {
|
headers: {
|
||||||
...(options || { headers: {} }).headers,
|
...(options || { headers: {} }).headers,
|
||||||
'Authorization': `Bearer ${bearer}`
|
'Authorization': `Bearer ${bearer}`
|
||||||
}
|
},
|
||||||
|
credentials: 'include'
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
//access the refreshed token via callback
|
//access the refreshed token via callback
|
||||||
const tokenCallback = async (cb) => {
|
const tokenCallback = async (cb) => {
|
||||||
|
//use this?
|
||||||
|
let bearer = accessToken;
|
||||||
|
|
||||||
//if expired (10 minutes, normally)
|
//if expired (10 minutes, normally)
|
||||||
const expired = new Date(decode(accessToken).exp * 1000) < Date.now();
|
const expired = new Date(jwtDecode(accessToken).exp) < Date.now() / 1000;
|
||||||
|
|
||||||
if (expired) {
|
if (expired) {
|
||||||
//ping the auth server for a new token
|
//ping the auth server for a new token
|
||||||
const response = await fetch(`${process.env.AUTH_URI}/auth/token`, {
|
const response = await fetch(`${process.env.AUTH_URI}/auth/token`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Authorization': `Bearer ${bearer}`
|
||||||
'Access-Control-Allow-Origin': '*'
|
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
credentials: 'include'
|
||||||
token: refreshToken
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//any errors, throw them
|
//any errors, throw them
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
if (response.status == 403) {
|
||||||
|
forceLogout();
|
||||||
|
}
|
||||||
throw `${response.status}: ${await response.text()}`;
|
throw `${response.status}: ${await response.text()}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +110,6 @@ const TokenProvider = props => {
|
|||||||
const newAuth = await response.json();
|
const newAuth = await response.json();
|
||||||
|
|
||||||
setAccessToken(newAuth.accessToken);
|
setAccessToken(newAuth.accessToken);
|
||||||
setRefreshToken(newAuth.refreshToken);
|
|
||||||
|
|
||||||
//finally
|
//finally
|
||||||
return cb(newAuth.accessToken);
|
return cb(newAuth.accessToken);
|
||||||
@@ -114,7 +119,7 @@ const TokenProvider = props => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TokenContext.Provider value={{ accessToken, refreshToken, setAccessToken, setRefreshToken, tokenFetch, tokenCallback, getPayload: () => decode(accessToken) }}>
|
<TokenContext.Provider value={{ accessToken, setAccessToken, tokenFetch, tokenCallback, getPayload: () => jwtDecode(accessToken) }}>
|
||||||
{props.children}
|
{props.children}
|
||||||
</TokenContext.Provider>
|
</TokenContext.Provider>
|
||||||
)
|
)
|
||||||
@@ -1,6 +1,14 @@
|
|||||||
|
/* clear from the rest of the CSS files */
|
||||||
|
|
||||||
|
.chat button, .chat input {
|
||||||
|
border-radius: unset !important;
|
||||||
|
font-size: unset !important;
|
||||||
|
margin: unset !important;
|
||||||
|
}
|
||||||
|
|
||||||
.chat {
|
.chat {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 23px;
|
bottom: 3.6em; /* Allow space for the footer */
|
||||||
right: 28px;
|
right: 28px;
|
||||||
width: 280px;
|
width: 280px;
|
||||||
border: solid;
|
border: solid;
|
||||||
@@ -8,71 +16,86 @@
|
|||||||
border-width: 2px;
|
border-width: 2px;
|
||||||
background-color: #CCC;
|
background-color: #CCC;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
max-height: calc(50vh - 23px);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.chat > button.open {
|
.chat button.open {
|
||||||
color: white;
|
color: white;
|
||||||
background-color: grey;
|
background-color: grey;
|
||||||
}
|
}
|
||||||
|
|
||||||
.chat > button.send {
|
.chat button.send {
|
||||||
color: white;
|
color: white;
|
||||||
background-color: green;
|
background-color: green;
|
||||||
|
border-style: solid;
|
||||||
|
border-width: 2px;
|
||||||
|
border-color: darkslategray;
|
||||||
}
|
}
|
||||||
|
|
||||||
.chat > button.close {
|
.chat button.close {
|
||||||
color: black;
|
color: black;
|
||||||
background-color: red;
|
background-color: red;
|
||||||
|
border-color: maroon;
|
||||||
|
border-width: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.chat > button {
|
.chat button {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 2em;
|
height: 2em;
|
||||||
opacity: 0.8;
|
opacity: 0.8;
|
||||||
|
border: unset;
|
||||||
}
|
}
|
||||||
|
|
||||||
.chat > button:hover {
|
.chat button:hover {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.chat > .input {
|
.chat .input {
|
||||||
width: calc(100% - 10px);
|
width: 100%;
|
||||||
height: 2em;
|
height: 2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.chat > .log {
|
.chat .log {
|
||||||
min-height: 300px;
|
min-height: 280px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.chat > .log > .scrollable > .line {
|
.chat .line {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
}
|
}
|
||||||
|
|
||||||
.chat > .log > .scrollable > .line > .report {
|
.chat .report {
|
||||||
color: red;
|
color: red;
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.chat > .log > .scrollable > .line:hover {
|
.chat .line:hover {
|
||||||
background-color: #BBB;
|
background-color: #BBB;
|
||||||
}
|
}
|
||||||
|
|
||||||
.chat > .log > .scrollable > .line:hover > .report {
|
.chat .line:hover .report {
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
.chat > .log > .scrollable > .line > .content > .username {
|
.chat .timestamp {
|
||||||
|
max-width: 44px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat .inner {
|
||||||
|
flex: 1 !important;
|
||||||
|
display: inline-block !important;
|
||||||
|
flex-direction: row !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat .username {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
.chat > .log > .scrollable {
|
.chat .scrollable {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
min-height: 280px;
|
min-height: 280px;
|
||||||
max-height: calc(50vh - 23px - 20px - 6em);
|
max-height: 180px;
|
||||||
overflow-x: wrap;
|
overflow-x: wrap;
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
}
|
}
|
||||||
@@ -80,3 +103,13 @@
|
|||||||
.chat ul {
|
.chat ul {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 768px) {
|
||||||
|
.chat {
|
||||||
|
position: unset;
|
||||||
|
bottom: unset;
|
||||||
|
right: unset;
|
||||||
|
width: calc(100% + 20px);
|
||||||
|
margin-left: -10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,323 @@
|
|||||||
|
/* global defaults */
|
||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
html {
|
||||||
|
scroll-behavior: smooth;
|
||||||
|
}
|
||||||
|
|
||||||
|
body, #root {
|
||||||
|
font: 12pt Helvetica, Arial;
|
||||||
|
min-width: 100vw;
|
||||||
|
min-height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
overflow-x: hidden;
|
||||||
|
overflow-y: auto;
|
||||||
|
background-color: #fefefe;
|
||||||
|
color: #010101;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 40pt;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-size: 24pt;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
font-size: 16pt;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul {
|
||||||
|
list-style-type: disc;
|
||||||
|
list-style-position: inside;
|
||||||
|
padding-bottom: .5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin-bottom: 0 !important;
|
||||||
|
padding-bottom: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
padding: 5px;
|
||||||
|
margin-bottom: 1em;
|
||||||
|
background-color: lightgray;
|
||||||
|
overflow-x: scroll;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: blue;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
blockquote {
|
||||||
|
padding-top: 0.5em;
|
||||||
|
padding-left: 1em;
|
||||||
|
margin-bottom: 1em;
|
||||||
|
border-left: 3px solid #ccc;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text.left {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text.centered {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text.right {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.centered {
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.middle {
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* header */
|
||||||
|
header {
|
||||||
|
flex: 0 1 auto;
|
||||||
|
margin-top: 1em;
|
||||||
|
margin-bottom: 1em;
|
||||||
|
justify-self: flex-start;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* footer */
|
||||||
|
footer {
|
||||||
|
padding-top: 0.5em;
|
||||||
|
flex: 0 1 auto;
|
||||||
|
justify-self: flex-end;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* central display */
|
||||||
|
.central {
|
||||||
|
padding: 0 10px;
|
||||||
|
margin: 0 20%;
|
||||||
|
min-height: calc(100vh - 3.6em);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 768px) {
|
||||||
|
.central {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* components */
|
||||||
|
.page {
|
||||||
|
flex: 1 0 auto;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page.centered {
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page.middle {
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel {
|
||||||
|
flex: 0 1 auto;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: flex-start;
|
||||||
|
padding-bottom: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel.centered {
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel.middle {
|
||||||
|
align-items: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
input, button {
|
||||||
|
text-indent: 0.3em;
|
||||||
|
border-radius: 0.2em;
|
||||||
|
font-size: 1.8em;
|
||||||
|
margin: 0.2em;
|
||||||
|
padding: 0.2em 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
margin-left: 0.5em;
|
||||||
|
margin-right: -0.4em;
|
||||||
|
max-height: none !important;
|
||||||
|
resize: vertical;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* "constrained" means reusable input area */
|
||||||
|
.constrained {
|
||||||
|
flex: 0 1 auto;
|
||||||
|
align-self: center;
|
||||||
|
max-width: 480px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
margin-bottom: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.constrained > * {
|
||||||
|
flex: 1 0 auto;
|
||||||
|
max-height: 2em;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
.constrained button, button.constrained {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.constrained label {
|
||||||
|
font-size: 1.8em;
|
||||||
|
text-indent: 0.4em;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 480px) {
|
||||||
|
.constrained {
|
||||||
|
max-width: 100vw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* flexbox tables */
|
||||||
|
.table {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table .row {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 480px) {
|
||||||
|
.table .row {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 768px) {
|
||||||
|
.table .row.tabletCollapse {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.table .row .col {
|
||||||
|
flex: 1 1 1%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table .row .col.double {
|
||||||
|
flex: 2 1 2%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table .row .col.half {
|
||||||
|
flex: 0.5 1 0.5%;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 480px) {
|
||||||
|
.table .row .col.double {
|
||||||
|
flex: 2 1 2.5%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.table.noCollapse .row, .table .row.noCollapse {
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* mobile control */
|
||||||
|
.mobile.show {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 480px) {
|
||||||
|
.mobile.centered {
|
||||||
|
text-align: initial;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile.show {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile.hide {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile.centered {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* hybrid of table and mobile control */
|
||||||
|
.mobile.hide.col {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile.col.half {
|
||||||
|
flex: 0.5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* tablet control */
|
||||||
|
.tablet.show {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 768px) {
|
||||||
|
.tablet.centered {
|
||||||
|
text-align: initial;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tablet.show {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tablet.hide {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tablet.centered {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* hybrid of table and tablet control */
|
||||||
|
.tablet.hide.col {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tablet.col.half {
|
||||||
|
flex: 0.5;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,6 @@
|
|||||||
<meta property="og:description" content="" />
|
<meta property="og:description" content="" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id = "root"></div>
|
<div id="root"></div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
+160
-40
@@ -36,7 +36,7 @@ const question = (prompt, def = null) => {
|
|||||||
|
|
||||||
Currently, all microservices are mandatory; you'll have to mess with the result
|
Currently, all microservices are mandatory; you'll have to mess with the result
|
||||||
and the source code if you wish to be more selective. Microservices currently
|
and the source code if you wish to be more selective. Microservices currently
|
||||||
impelented are:
|
implemented are:
|
||||||
|
|
||||||
* auth-server
|
* auth-server
|
||||||
* news-server
|
* news-server
|
||||||
@@ -46,24 +46,90 @@ See https://github.com/krgamestudios/MERN-template/wiki for help.
|
|||||||
`
|
`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// //determine local computer address for mac user vs everyone else
|
||||||
|
// let macUser = '';
|
||||||
|
// while (macUser.toLowerCase() !== 'yes' && macUser.toLowerCase() !== 'no') {
|
||||||
|
// macUser = await question('Will the MERN-Template be running locally on a MacOS system? (yes or no, this only alters startup.sql)', '');
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const localAddress = macUser === 'yes' ? 'localhost' : '%';
|
||||||
|
const localAddress = '%';
|
||||||
|
|
||||||
//project configuration
|
//project configuration
|
||||||
const projectName = await question('Project Name', 'template');
|
const projectName = await question('Project Name', 'template');
|
||||||
const projectWebAddress = await question('Project Web Address', 'example.com');
|
const projectWebAddress = await question('Project Web Address', 'example.com');
|
||||||
|
|
||||||
|
const corsWebOrigin = await question('CORS Web Origin', `https://${projectWebAddress}`);
|
||||||
|
|
||||||
|
let projectDBLocation = '';
|
||||||
|
while (typeof projectDBLocation != 'string' || /^[le]/i.test(projectDBLocation[0]) == false) {
|
||||||
|
projectDBLocation = await question('Project [l]ocal or [e]xternal database?');
|
||||||
|
}
|
||||||
|
|
||||||
|
let projectDBHost = '';
|
||||||
|
let projectDBPort = '';
|
||||||
|
|
||||||
|
if (/^[l]/i.test(projectDBLocation[0])) {
|
||||||
|
projectDBHost = 'database';
|
||||||
|
projectDBPort = '3306';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
projectDBHost = await question('Project DB Host');
|
||||||
|
projectDBPort = await question('Project DB Port', '3306');
|
||||||
|
}
|
||||||
|
|
||||||
const projectDBUser = await question('Project DB Username', projectName);
|
const projectDBUser = await question('Project DB Username', projectName);
|
||||||
const projectDBPass = await question('Project DB Password', 'pikachu');
|
const projectDBPass = await question('Project DB Password', 'pikachu');
|
||||||
|
|
||||||
//news configuration
|
//news configuration
|
||||||
const newsName = await question('News Name', 'news');
|
const newsName = await question('News Name', 'news');
|
||||||
const newsWebAddress = await question('News Web Address', `${newsName}.${projectWebAddress}`);
|
const newsWebAddress = await question('News Web Address', `${newsName}.${projectWebAddress}`);
|
||||||
const newsDBUser = await question('News DB Username', newsName);
|
|
||||||
const newsDBPass = await question('News DB Password', 'charizard');
|
let newsDBLocation = '';
|
||||||
|
while (typeof newsDBLocation != 'string' || /^[le]/i.test(newsDBLocation[0]) == false) {
|
||||||
|
newsDBLocation = await question('News [l]ocal or [e]xternal database?');
|
||||||
|
}
|
||||||
|
|
||||||
|
let newsDBHost = '';
|
||||||
|
let newsDBPort = '';
|
||||||
|
|
||||||
|
if (/^[l]/i.test(newsDBLocation[0])) {
|
||||||
|
newsDBHost = 'database';
|
||||||
|
newsDBPort = '3306';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
newsDBHost = await question('News DB Host');
|
||||||
|
newsDBPort = await question('News DB Port', '3306');
|
||||||
|
}
|
||||||
|
|
||||||
|
const newsDBUser = await question('News DB Username', newsName);
|
||||||
|
const newsDBPass = await question('News DB Password', 'venusaur');
|
||||||
|
|
||||||
//auth configuration
|
//auth configuration
|
||||||
const authName = await question('Auth Name', 'auth');
|
const authName = await question('Auth Name', 'auth');
|
||||||
const authWebAddress = await question('Auth Web Address', `${authName}.${projectWebAddress}`);
|
const authWebAddress = await question('Auth Web Address', `${authName}.${projectWebAddress}`);
|
||||||
const authDBUser = await question('Auth DB Username', authName);
|
const authPostValidationHookArray = await question('Auth Post Validation Hook Array', '');
|
||||||
const authDBPass = await question('Auth DB Password', 'venusaur');
|
const authResetAddress = await question('Auth Reset Addr', `${projectWebAddress}/reset`);
|
||||||
|
|
||||||
|
let authDBLocation = '';
|
||||||
|
while (typeof authDBLocation != 'string' || /^[le]/i.test(authDBLocation[0]) == false) {
|
||||||
|
authDBLocation = await question('Auth [l]ocal or [e]xternal database?');
|
||||||
|
}
|
||||||
|
|
||||||
|
let authDBHost = '';
|
||||||
|
let authDBPort = '';
|
||||||
|
|
||||||
|
if (/^[l]/i.test(authDBLocation[0])) {
|
||||||
|
authDBHost = 'database';
|
||||||
|
authDBPort = '3306';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
authDBHost = await question('Auth DB Host');
|
||||||
|
authDBPort = await question('Auth DB Port', '3306');
|
||||||
|
}
|
||||||
|
|
||||||
|
const authDBUser = await question('Auth DB Username', authName);
|
||||||
|
const authDBPass = await question('Auth DB Password', 'charizard');
|
||||||
|
|
||||||
const emailSMTP = await question('Email SMTP', 'smtp.example.com');
|
const emailSMTP = await question('Email SMTP', 'smtp.example.com');
|
||||||
const emailUser = await question('Email Address', 'foobar@example.com');
|
const emailUser = await question('Email Address', 'foobar@example.com');
|
||||||
@@ -73,7 +139,25 @@ See https://github.com/krgamestudios/MERN-template/wiki for help.
|
|||||||
//chat goes here
|
//chat goes here
|
||||||
const chatName = await question('Chat Name', 'chat');
|
const chatName = await question('Chat Name', 'chat');
|
||||||
const chatWebAddress = await question('Chat Web Address', `${chatName}.${projectWebAddress}`);
|
const chatWebAddress = await question('Chat Web Address', `${chatName}.${projectWebAddress}`);
|
||||||
const chatDBUser = await question('Chat DB Username', chatName);
|
|
||||||
|
let chatDBLocation = '';
|
||||||
|
while (typeof chatDBLocation != 'string' || /^[le]/i.test(chatDBLocation[0]) == false) {
|
||||||
|
chatDBLocation = await question('Chat [l]ocal or [e]xternal database?');
|
||||||
|
}
|
||||||
|
|
||||||
|
let chatDBHost = '';
|
||||||
|
let chatDBPort = '';
|
||||||
|
|
||||||
|
if (/^[l]/i.test(chatDBLocation[0])) {
|
||||||
|
chatDBHost = 'database';
|
||||||
|
chatDBPort = '3306';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
chatDBHost = await question('Chat DB Host');
|
||||||
|
chatDBPort = await question('Chat DB Port', '3306');
|
||||||
|
}
|
||||||
|
|
||||||
|
const chatDBUser = await question('Chat DB Username', chatName);
|
||||||
const chatDBPass = await question('Chat DB Password', 'blastoise');
|
const chatDBPass = await question('Chat DB Password', 'blastoise');
|
||||||
|
|
||||||
//database configuration
|
//database configuration
|
||||||
@@ -89,32 +173,34 @@ See https://github.com/krgamestudios/MERN-template/wiki for help.
|
|||||||
|
|
||||||
//MUST be at least 8 chars
|
//MUST be at least 8 chars
|
||||||
let tmpPass = '';
|
let tmpPass = '';
|
||||||
|
let tmpHost = '';
|
||||||
while (defaultUser && tmpPass.length < 8) {
|
while (defaultUser && tmpPass.length < 8) {
|
||||||
console.log('--All passwords must be at least 8 characters long--');
|
console.log('--All passwords must be at least 8 characters long--');
|
||||||
tmpPass = await question('Default Admin Pass', '');
|
tmpPass = await question('Default Admin Pass', '');
|
||||||
|
tmpHost = await question('Default Admin Host', '');
|
||||||
}
|
}
|
||||||
const defaultPass = tmpPass;
|
const defaultPass = tmpPass;
|
||||||
|
const defaultHost = tmpHost;
|
||||||
|
|
||||||
if (defaultUser) {
|
if (defaultUser) {
|
||||||
console.log(`Default user email will be: ${defaultUser}@${authWebAddress}`);
|
console.log(`Default user email will be: ${defaultUser}@${defaultHost}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
//traefic configuration
|
//traefic configuration
|
||||||
const supportEmail = await question('Support Email', emailUser);
|
const supportEmail = await question('Support Email', emailUser);
|
||||||
|
|
||||||
//misc. configuration
|
//misc. configuration
|
||||||
const projectPort = 3000;
|
const projectPort = '3000';
|
||||||
const newsPort = 3100;
|
const newsPort = '3100';
|
||||||
const authPort = 3200;
|
const authPort = '3200';
|
||||||
const chatPort = 3300;
|
const chatPort = '3300';
|
||||||
|
|
||||||
const ymlfile = `
|
const ymlfile = `
|
||||||
version: "3.6"
|
|
||||||
services:
|
services:
|
||||||
${projectName}:
|
${projectName}:
|
||||||
build: .
|
build: .
|
||||||
ports:
|
ports:
|
||||||
- "${projectPort}"
|
- ${projectPort}
|
||||||
labels:
|
labels:
|
||||||
- traefik.enable=true
|
- traefik.enable=true
|
||||||
- traefik.http.routers.${projectName}router.rule=Host(\`${projectWebAddress}\`)
|
- traefik.http.routers.${projectName}router.rule=Host(\`${projectWebAddress}\`)
|
||||||
@@ -123,8 +209,10 @@ services:
|
|||||||
- traefik.http.routers.${projectName}router.service=${projectName}service@docker
|
- traefik.http.routers.${projectName}router.service=${projectName}service@docker
|
||||||
- traefik.http.services.${projectName}service.loadbalancer.server.port=${projectPort}
|
- traefik.http.services.${projectName}service.loadbalancer.server.port=${projectPort}
|
||||||
environment:
|
environment:
|
||||||
|
- WEB_ORIGIN=${corsWebOrigin}
|
||||||
- WEB_PORT=${projectPort}
|
- WEB_PORT=${projectPort}
|
||||||
- DB_HOSTNAME=database
|
- DB_HOSTNAME=${projectDBHost}
|
||||||
|
- DB_PORTNAME=${projectDBPort}
|
||||||
- DB_DATABASE=${projectName}
|
- DB_DATABASE=${projectName}
|
||||||
- DB_USERNAME=${projectDBUser}
|
- DB_USERNAME=${projectDBUser}
|
||||||
- DB_PASSWORD=${projectDBPass}
|
- DB_PASSWORD=${projectDBPass}
|
||||||
@@ -133,10 +221,13 @@ services:
|
|||||||
- AUTH_URI=https://${authWebAddress}
|
- AUTH_URI=https://${authWebAddress}
|
||||||
- CHAT_URI=https://${chatWebAddress}
|
- CHAT_URI=https://${chatWebAddress}
|
||||||
- SECRET_ACCESS=${accessToken}
|
- SECRET_ACCESS=${accessToken}
|
||||||
|
volumes:
|
||||||
|
- /etc/timezone:/etc/timezone:ro
|
||||||
|
- /etc/localtime:/etc/localtime:ro
|
||||||
networks:
|
networks:
|
||||||
- app-network
|
- app-network
|
||||||
depends_on:
|
depends_on:${ projectDBHost != 'database' ? '' : `
|
||||||
- database
|
- database`}
|
||||||
- traefik
|
- traefik
|
||||||
|
|
||||||
${newsName}:
|
${newsName}:
|
||||||
@@ -151,18 +242,23 @@ services:
|
|||||||
- traefik.http.routers.${newsName}router.service=${newsName}service@docker
|
- traefik.http.routers.${newsName}router.service=${newsName}service@docker
|
||||||
- traefik.http.services.${newsName}service.loadbalancer.server.port=${newsPort}
|
- traefik.http.services.${newsName}service.loadbalancer.server.port=${newsPort}
|
||||||
environment:
|
environment:
|
||||||
|
- WEB_ORIGIN=${corsWebOrigin}
|
||||||
- WEB_PORT=${newsPort}
|
- WEB_PORT=${newsPort}
|
||||||
- DB_HOSTNAME=database
|
- DB_HOSTNAME=${newsDBHost}
|
||||||
|
- DB_PORTNAME=${newsDBPort}
|
||||||
- DB_DATABASE=${newsName}
|
- DB_DATABASE=${newsName}
|
||||||
- DB_USERNAME=${newsDBUser}
|
- DB_USERNAME=${newsDBUser}
|
||||||
- DB_PASSWORD=${newsDBPass}
|
- DB_PASSWORD=${newsDBPass}
|
||||||
- DB_TIMEZONE=${dbTimeZone}
|
- DB_TIMEZONE=${dbTimeZone}
|
||||||
- QUERY_LIMIT=10
|
- PAGE_SIZE=10
|
||||||
- SECRET_ACCESS=${accessToken}
|
- SECRET_ACCESS=${accessToken}
|
||||||
|
volumes:
|
||||||
|
- /etc/timezone:/etc/timezone:ro
|
||||||
|
- /etc/localtime:/etc/localtime:ro
|
||||||
networks:
|
networks:
|
||||||
- app-network
|
- app-network
|
||||||
depends_on:
|
depends_on:${ newsDBHost != 'database' ? '' : `
|
||||||
- database
|
- database`}
|
||||||
- traefik
|
- traefik
|
||||||
|
|
||||||
${authName}:
|
${authName}:
|
||||||
@@ -177,10 +273,14 @@ services:
|
|||||||
- traefik.http.routers.${authName}router.service=${authName}service@docker
|
- traefik.http.routers.${authName}router.service=${authName}service@docker
|
||||||
- traefik.http.services.${authName}service.loadbalancer.server.port=${authPort}
|
- traefik.http.services.${authName}service.loadbalancer.server.port=${authPort}
|
||||||
environment:
|
environment:
|
||||||
|
- WEB_ORIGIN=${corsWebOrigin}
|
||||||
- WEB_PROTOCOL=https
|
- WEB_PROTOCOL=https
|
||||||
- WEB_ADDRESS=${authWebAddress}
|
- WEB_ADDRESS=${authWebAddress}
|
||||||
|
- HOOK_POST_VALIDATION_ARRAY=${authPostValidationHookArray}
|
||||||
|
- WEB_RESET_ADDRESS=${authResetAddress}
|
||||||
- WEB_PORT=${authPort}
|
- WEB_PORT=${authPort}
|
||||||
- DB_HOSTNAME=database
|
- DB_HOSTNAME=${authDBHost}
|
||||||
|
- DB_PORTNAME=${authDBPort}
|
||||||
- DB_DATABASE=${authName}
|
- DB_DATABASE=${authName}
|
||||||
- DB_USERNAME=${authDBUser}
|
- DB_USERNAME=${authDBUser}
|
||||||
- DB_PASSWORD=${authDBPass}
|
- DB_PASSWORD=${authDBPass}
|
||||||
@@ -190,13 +290,17 @@ services:
|
|||||||
- MAIL_PASSWORD=${emailPass}
|
- MAIL_PASSWORD=${emailPass}
|
||||||
- MAIL_PHYSICAL=${emailPhysical}
|
- MAIL_PHYSICAL=${emailPhysical}
|
||||||
- ADMIN_DEFAULT_USERNAME=${defaultUser}
|
- ADMIN_DEFAULT_USERNAME=${defaultUser}
|
||||||
|
- ADMIN_DEFAULT_HOSTNAME=${defaultHost}
|
||||||
- ADMIN_DEFAULT_PASSWORD=${defaultPass}
|
- ADMIN_DEFAULT_PASSWORD=${defaultPass}
|
||||||
- SECRET_ACCESS=${accessToken}
|
- SECRET_ACCESS=${accessToken}
|
||||||
- SECRET_REFRESH=${refreshToken}
|
- SECRET_REFRESH=${refreshToken}
|
||||||
|
volumes:
|
||||||
|
- /etc/timezone:/etc/timezone:ro
|
||||||
|
- /etc/localtime:/etc/localtime:ro
|
||||||
networks:
|
networks:
|
||||||
- app-network
|
- app-network
|
||||||
depends_on:
|
depends_on:${ authDBHost != 'database' ? '' : `
|
||||||
- database
|
- database`}
|
||||||
- traefik
|
- traefik
|
||||||
|
|
||||||
${chatName}:
|
${chatName}:
|
||||||
@@ -211,19 +315,25 @@ services:
|
|||||||
- traefik.http.routers.${chatName}router.service=${chatName}service@docker
|
- traefik.http.routers.${chatName}router.service=${chatName}service@docker
|
||||||
- traefik.http.services.${chatName}service.loadbalancer.server.port=${chatPort}
|
- traefik.http.services.${chatName}service.loadbalancer.server.port=${chatPort}
|
||||||
environment:
|
environment:
|
||||||
|
- WEB_ORIGIN=${corsWebOrigin}
|
||||||
- WEB_PORT=${chatPort}
|
- WEB_PORT=${chatPort}
|
||||||
- DB_HOSTNAME=database
|
- DB_HOSTNAME=${chatDBHost}
|
||||||
|
- DB_PORTNAME=${chatDBPort}
|
||||||
- DB_DATABASE=${chatName}
|
- DB_DATABASE=${chatName}
|
||||||
- DB_USERNAME=${chatDBUser}
|
- DB_USERNAME=${chatDBUser}
|
||||||
- DB_PASSWORD=${chatDBPass}
|
- DB_PASSWORD=${chatDBPass}
|
||||||
- DB_TIMEZONE=${dbTimeZone}
|
- DB_TIMEZONE=${dbTimeZone}
|
||||||
- SECRET_ACCESS=${accessToken}
|
- SECRET_ACCESS=${accessToken}
|
||||||
|
volumes:
|
||||||
|
- /etc/timezone:/etc/timezone:ro
|
||||||
|
- /etc/localtime:/etc/localtime:ro
|
||||||
networks:
|
networks:
|
||||||
- app-network
|
- app-network
|
||||||
depends_on:
|
depends_on:${ chatDBHost != 'database' ? '' : `
|
||||||
- database
|
- database`}
|
||||||
- traefik
|
- traefik
|
||||||
|
|
||||||
|
${ [projectDBHost, newsDBHost, authDBHost, chatDBHost].some(x => x == "database") == false ? '' : `
|
||||||
database:
|
database:
|
||||||
image: mariadb
|
image: mariadb
|
||||||
restart: always
|
restart: always
|
||||||
@@ -232,28 +342,35 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- ./mysql:/var/lib/mysql
|
- ./mysql:/var/lib/mysql
|
||||||
- ./startup.sql:/docker-entrypoint-initdb.d/startup.sql:ro
|
- ./startup.sql:/docker-entrypoint-initdb.d/startup.sql:ro
|
||||||
|
- /etc/timezone:/etc/timezone:ro
|
||||||
|
- /etc/localtime:/etc/localtime:ro
|
||||||
networks:
|
networks:
|
||||||
- app-network
|
- app-network
|
||||||
|
`}
|
||||||
traefik:
|
traefik:
|
||||||
image: traefik:v2.4
|
image: traefik:latest
|
||||||
container_name: traefik
|
container_name: traefik
|
||||||
command:
|
command:
|
||||||
- --log.level=ERROR
|
- --log.level=ERROR
|
||||||
- --api.insecure=false
|
- --api.insecure=false
|
||||||
- --providers.docker=true
|
- --providers.docker=true
|
||||||
- --providers.docker.exposedbydefault=false
|
- --providers.docker.exposedbydefault=false
|
||||||
|
- --entrypoints.web.address=:80
|
||||||
|
- --entrypoints.web.http.redirections.entryPoint.to=websecure
|
||||||
|
- --entrypoints.web.http.redirections.entryPoint.scheme=https
|
||||||
|
- --entrypoints.web.http.redirections.entrypoint.permanent=true
|
||||||
- --entrypoints.websecure.address=:443
|
- --entrypoints.websecure.address=:443
|
||||||
- --certificatesresolvers.myresolver.acme.tlschallenge=true
|
- --certificatesresolvers.myresolver.acme.tlschallenge=true
|
||||||
- --certificatesresolvers.myresolver.acme.email=${supportEmail}
|
- --certificatesresolvers.myresolver.acme.email=${supportEmail}
|
||||||
- --certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json
|
- --certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json
|
||||||
- traefik.docker.network=app-network
|
|
||||||
ports:
|
ports:
|
||||||
- 80:80
|
- 80:80
|
||||||
- 443:443
|
- 443:443
|
||||||
volumes:
|
volumes:
|
||||||
- ./letsencrypt:/letsencrypt
|
- ./letsencrypt:/letsencrypt
|
||||||
- /var/run/docker.sock:/var/run/docker.sock:ro
|
- /var/run/docker.sock:/var/run/docker.sock:ro
|
||||||
|
- /etc/timezone:/etc/timezone:ro
|
||||||
|
- /etc/localtime:/etc/localtime:ro
|
||||||
networks:
|
networks:
|
||||||
- app-network
|
- app-network
|
||||||
|
|
||||||
@@ -263,36 +380,39 @@ networks:
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
const dockerfile = `
|
const dockerfile = `
|
||||||
FROM node:15
|
FROM node:22-bookworm-slim
|
||||||
WORKDIR "/app"
|
WORKDIR "/app"
|
||||||
COPY package*.json ./
|
|
||||||
RUN npm install
|
|
||||||
COPY . /app
|
COPY . /app
|
||||||
|
RUN mkdir -p /app/public
|
||||||
|
RUN chown node:node /app/public
|
||||||
|
RUN npm install --production
|
||||||
EXPOSE ${projectPort}
|
EXPOSE ${projectPort}
|
||||||
|
USER node
|
||||||
ENTRYPOINT ["bash", "-c"]
|
ENTRYPOINT ["bash", "-c"]
|
||||||
CMD ["sleep 10 && npm start"]
|
CMD ["sleep 10 && npm start"]
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const sqlfile = `
|
const sqlfile = `
|
||||||
CREATE DATABASE IF NOT EXISTS ${projectName};
|
CREATE DATABASE IF NOT EXISTS ${projectName};
|
||||||
CREATE USER IF NOT EXISTS '${projectDBUser}'@'%' IDENTIFIED BY '${projectDBPass}';
|
CREATE USER IF NOT EXISTS '${projectDBUser}'@'${localAddress}' IDENTIFIED BY '${projectDBPass}';
|
||||||
GRANT ALL PRIVILEGES ON ${projectName}.* TO '${projectDBUser}'@'%';
|
GRANT ALL PRIVILEGES ON ${projectName}.* TO '${projectDBUser}'@'${localAddress}';
|
||||||
|
|
||||||
CREATE DATABASE IF NOT EXISTS ${newsName};
|
CREATE DATABASE IF NOT EXISTS ${newsName};
|
||||||
CREATE USER IF NOT EXISTS '${newsDBUser}'@'%' IDENTIFIED BY '${newsDBPass}';
|
CREATE USER IF NOT EXISTS '${newsDBUser}'@'${localAddress}' IDENTIFIED BY '${newsDBPass}';
|
||||||
GRANT ALL PRIVILEGES ON ${newsName}.* TO '${newsDBUser}'@'%';
|
GRANT ALL PRIVILEGES ON ${newsName}.* TO '${newsDBUser}'@'${localAddress}';
|
||||||
|
|
||||||
CREATE DATABASE IF NOT EXISTS ${authName};
|
CREATE DATABASE IF NOT EXISTS ${authName};
|
||||||
CREATE USER IF NOT EXISTS '${authDBUser}'@'%' IDENTIFIED BY '${authDBPass}';
|
CREATE USER IF NOT EXISTS '${authDBUser}'@'${localAddress}' IDENTIFIED BY '${authDBPass}';
|
||||||
GRANT ALL PRIVILEGES ON ${authName}.* TO '${authDBUser}'@'%';
|
GRANT ALL PRIVILEGES ON ${authName}.* TO '${authDBUser}'@'${localAddress}';
|
||||||
|
|
||||||
CREATE DATABASE IF NOT EXISTS ${chatName};
|
CREATE DATABASE IF NOT EXISTS ${chatName};
|
||||||
CREATE USER IF NOT EXISTS '${chatDBUser}'@'%' IDENTIFIED BY '${chatDBPass}';
|
CREATE USER IF NOT EXISTS '${chatDBUser}'@'${localAddress}' IDENTIFIED BY '${chatDBPass}';
|
||||||
GRANT ALL PRIVILEGES ON ${chatName}.* TO '${chatDBUser}'@'%';
|
GRANT ALL PRIVILEGES ON ${chatName}.* TO '${chatDBUser}'@'${localAddress}';
|
||||||
|
|
||||||
FLUSH PRIVILEGES;
|
FLUSH PRIVILEGES;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
||||||
fs.writeFileSync('docker-compose.yml', ymlfile);
|
fs.writeFileSync('docker-compose.yml', ymlfile);
|
||||||
fs.writeFileSync('Dockerfile', dockerfile);
|
fs.writeFileSync('Dockerfile', dockerfile);
|
||||||
fs.writeFileSync('startup.sql', sqlfile);
|
fs.writeFileSync('startup.sql', sqlfile);
|
||||||
|
|||||||
Generated
+4879
-16469
File diff suppressed because it is too large
Load Diff
+32
-37
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "mern-template",
|
"name": "mern-template",
|
||||||
"version": "1.0.1",
|
"version": "1.5.4",
|
||||||
"description": "A website template using the MERN stack.",
|
"description": "A website template using the MERN stack.",
|
||||||
"main": "server/server.js",
|
"main": "server/server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -8,54 +8,49 @@
|
|||||||
"build": "npm run build:server && npm run build:client",
|
"build": "npm run build:server && npm run build:client",
|
||||||
"build:server": "exit 0",
|
"build:server": "exit 0",
|
||||||
"build:client": "webpack --env=production --config webpack.config.js",
|
"build:client": "webpack --env=production --config webpack.config.js",
|
||||||
"dev": "concurrently npm:watch:server npm:watch:client",
|
"dev": "concurrently npm:dev:server npm:dev:client",
|
||||||
"watch:server": "nodemon ./* --ext js,jsx,json --ignore 'node_modules/*'",
|
"dev:server": "nodemon --ext js,jsx,json --ignore 'node_modules/*'",
|
||||||
"watch:client": "webpack serve --env=development --config webpack.config.js",
|
"dev:client": "webpack serve --config webpack.config.js",
|
||||||
"analyzer": "webpack --env=production --analyzer --config webpack.config.js"
|
"analyze": "webpack --env=production --env=analyze --config webpack.config.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/KRGameStudios/MERN-template.git"
|
"url": "git+https://github.com/KRGameStudios/MERN-template.git"
|
||||||
},
|
},
|
||||||
"author": "Kayne Ruse",
|
"author": "Kayne Ruse",
|
||||||
"license": "ISC",
|
"license": "Zlib",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/KRGameStudios/MERN-template/issues"
|
"url": "https://github.com/KRGameStudios/MERN-template/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/KRGameStudios/MERN-template#readme",
|
"homepage": "https://github.com/KRGameStudios/MERN-template#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/core": ">=7.12.10",
|
"@babel/core": "^7.28.4",
|
||||||
"@babel/preset-env": ">=7.12.11",
|
"@babel/preset-env": "^7.28.3",
|
||||||
"@babel/preset-react": ">=7.12.10",
|
"@babel/preset-react": "^7.27.1",
|
||||||
"@loadable/component": ">=5.14.1",
|
"babel-loader": "^10.0.0",
|
||||||
"babel-loader": ">=8.2.2",
|
"clean-webpack-plugin": "^4.0.0",
|
||||||
"clean-webpack-plugin": ">=3.0.0",
|
"compression-webpack-plugin": "^11.1.0",
|
||||||
"concurrently": ">=5.3.0",
|
"concurrently": "^9.2.1",
|
||||||
"css-loader": ">=5.1.3",
|
"css-loader": "^7.1.2",
|
||||||
"dateformat": ">=4.5.1",
|
"dateformat": "^5.0.3",
|
||||||
"dotenv": ">=8.2.0",
|
"dotenv": "^17.2.2",
|
||||||
"express": ">=4.17.1",
|
"express": "^5.1.0",
|
||||||
"html-webpack-plugin": ">=5.0.0-alpha.14",
|
"html-webpack-plugin": "^5.6.4",
|
||||||
"jwt-decode": ">=3.1.2",
|
"jwt-decode": "^4.0.0",
|
||||||
"mariadb": ">=2.5.2",
|
"mariadb": "^3.4.5",
|
||||||
"raw-loader": ">=4.0.2",
|
"react": "^19.1.1",
|
||||||
"react": ">=17.0.1",
|
"react-dom": "^19.1.1",
|
||||||
"react-dom": ">=17.0.1",
|
"react-router": "^7.7.1",
|
||||||
"react-dropdown-select": ">=4.7.4",
|
"react-select": "^5.10.2",
|
||||||
"react-markdown": ">=5.0.3",
|
"sequelize": "^6.37.7",
|
||||||
"react-router": ">=5.2.0",
|
"socket.io-client": "^4.8.1",
|
||||||
"react-router-dom": ">=5.2.0",
|
"style-loader": "^4.0.0",
|
||||||
"rehype-raw": "^5.1.0",
|
"webpack": "^5.101.3",
|
||||||
"sequelize": ">=6.4.0",
|
"webpack-bundle-analyzer": "^4.10.2",
|
||||||
"socket.io-client": ">=4.0.0",
|
"webpack-cli": "^6.0.1"
|
||||||
"style-loader": ">=2.0.0",
|
|
||||||
"universal-cookie": ">=4.0.4",
|
|
||||||
"webpack": ">=5.15.0",
|
|
||||||
"webpack-cli": ">=4.3.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"nodemon": ">=2.0.7",
|
"nodemon": "^3.1.10",
|
||||||
"webpack-bundle-analyzer": ">=4.3.0",
|
"webpack-dev-server": "^5.2.2"
|
||||||
"webpack-dev-server": ">=1.16.5"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,10 @@ const Sequelize = require('sequelize');
|
|||||||
|
|
||||||
const sequelize = new Sequelize(process.env.DB_DATABASE, process.env.DB_USERNAME, process.env.DB_PASSWORD, {
|
const sequelize = new Sequelize(process.env.DB_DATABASE, process.env.DB_USERNAME, process.env.DB_PASSWORD, {
|
||||||
host: process.env.DB_HOSTNAME,
|
host: process.env.DB_HOSTNAME,
|
||||||
|
port: process.env.DB_PORTNAME,
|
||||||
dialect: 'mariadb',
|
dialect: 'mariadb',
|
||||||
timezone: process.env.DB_TIMEZONE,
|
timezone: process.env.DB_TIMEZONE,
|
||||||
logging: process.env.DB_LOGGING ? console.log : false
|
logging: process.env.DB_LOGGING ? console.log : false
|
||||||
});
|
});
|
||||||
|
|
||||||
sequelize.sync();
|
module.exports = sequelize;
|
||||||
|
|
||||||
module.exports = sequelize;
|
|
||||||
+18
-3
@@ -8,10 +8,24 @@ const path = require('path');
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const app = express();
|
const app = express();
|
||||||
const server = require('http').Server(app);
|
const server = require('http').Server(app);
|
||||||
const bodyParser = require('body-parser');
|
|
||||||
|
|
||||||
//config
|
//config
|
||||||
app.use(bodyParser.json());
|
app.use(express.json());
|
||||||
|
|
||||||
|
//handle compressed files (middleware)
|
||||||
|
app.get('/{*any}.js', (req, res, next) => {
|
||||||
|
req.url = req.url + '.gz';
|
||||||
|
res.set('Content-Encoding', 'gzip');
|
||||||
|
res.set('Content-Type', 'text/javascript');
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/{*any}.css', (req, res, next) => {
|
||||||
|
req.url = req.url + '.gz';
|
||||||
|
res.set('Content-Encoding', 'gzip');
|
||||||
|
res.set('Content-Type', 'text/css');
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
//database connection
|
//database connection
|
||||||
const database = require('./database');
|
const database = require('./database');
|
||||||
@@ -20,7 +34,7 @@ const database = require('./database');
|
|||||||
app.use('/', express.static(path.resolve(__dirname, '..', 'public')));
|
app.use('/', express.static(path.resolve(__dirname, '..', 'public')));
|
||||||
|
|
||||||
//fallback to the index file
|
//fallback to the index file
|
||||||
app.get('*', (req, res) => {
|
app.get('/{*any}', (req, res) => {
|
||||||
res.sendFile(path.resolve(__dirname, '..', 'public' , 'index.html'));
|
res.sendFile(path.resolve(__dirname, '..', 'public' , 'index.html'));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -28,4 +42,5 @@ app.get('*', (req, res) => {
|
|||||||
server.listen(process.env.WEB_PORT || 3000, async (err) => {
|
server.listen(process.env.WEB_PORT || 3000, async (err) => {
|
||||||
await database.sync();
|
await database.sync();
|
||||||
console.log(`listening to localhost:${process.env.WEB_PORT || 3000}`);
|
console.log(`listening to localhost:${process.env.WEB_PORT || 3000}`);
|
||||||
|
console.log(`database located at ${process.env.DB_HOSTNAME || '<default>'}:${process.env.DB_PORTNAME || '<default>'}`);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
#This file only needs to be run once, during initial development setup
|
|
||||||
#This file isnt needed for actual deployment
|
|
||||||
|
|
||||||
#Create the development database
|
|
||||||
CREATE DATABASE IF NOT EXISTS template;
|
|
||||||
USE template;
|
|
||||||
|
|
||||||
#Create the database user
|
|
||||||
CREATE USER IF NOT EXISTS 'template'@'%' IDENTIFIED BY 'pikachu';
|
|
||||||
GRANT ALL PRIVILEGES ON template.* TO 'template'@'%';
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
#use this while debugging
|
||||||
|
CREATE DATABASE template;
|
||||||
|
CREATE USER 'template'@'%' IDENTIFIED BY 'pikachu';
|
||||||
|
GRANT ALL PRIVILEGES ON template.* TO 'template'@'%';
|
||||||
|
|
||||||
+105
-116
@@ -1,116 +1,105 @@
|
|||||||
//plugins
|
//plugins
|
||||||
const { DefinePlugin } = require('webpack');
|
const { DefinePlugin } = require('webpack');
|
||||||
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
||||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||||
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
const CompressionPlugin = require('compression-webpack-plugin');
|
||||||
|
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
||||||
//libraries
|
|
||||||
const path = require('path');
|
//libraries
|
||||||
|
const path = require('path');
|
||||||
//the exported config function
|
|
||||||
module.exports = ({ production, analyzer }) => {
|
//the exported config function
|
||||||
|
module.exports = ({ production, analyze }) => {
|
||||||
return {
|
return {
|
||||||
mode: production ? "production" : "development",
|
mode: production ? "production" : "development",
|
||||||
entry: path.resolve(__dirname, 'client', 'client.jsx'),
|
entry: path.resolve(__dirname, 'client', 'client.jsx'),
|
||||||
output: {
|
output: {
|
||||||
path: path.resolve(__dirname, 'public'),
|
path: path.resolve(__dirname, 'public'),
|
||||||
filename: '[name].[chunkhash].js',
|
publicPath: '/',
|
||||||
sourceMapFilename: '[name].[chunkhash].js.map'
|
filename: '[name].[chunkhash].js',
|
||||||
},
|
sourceMapFilename: '[name].[chunkhash].js.map'
|
||||||
devtool: production ? 'source-map' : 'eval-source-map',
|
},
|
||||||
resolve: {
|
devtool: production ? false : 'eval-source-map',
|
||||||
extensions: ['.js', '.jsx']
|
resolve: {
|
||||||
},
|
extensions: ['.js', '.jsx']
|
||||||
module: {
|
},
|
||||||
rules: [
|
module: {
|
||||||
{
|
rules: [
|
||||||
test: /\.(js|jsx)$/,
|
{
|
||||||
exclude: /(node_modules)/,
|
test: /\.(js|jsx)$/,
|
||||||
use: [
|
exclude: /(node_modules)/,
|
||||||
{
|
use: [
|
||||||
loader: 'babel-loader',
|
{
|
||||||
options: {
|
loader: 'babel-loader',
|
||||||
presets: ['@babel/preset-env', '@babel/preset-react'],
|
options: {
|
||||||
plugins: ['@babel/plugin-syntax-dynamic-import']
|
presets: ['@babel/preset-env', '@babel/preset-react'],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: /\.(css)$/,
|
test: /\.(css)$/,
|
||||||
use: ['style-loader', 'css-loader']
|
use: ['style-loader', 'css-loader']
|
||||||
},
|
},
|
||||||
{
|
]
|
||||||
test: /\.(md)$/,
|
},
|
||||||
use: [
|
plugins: [
|
||||||
{
|
new DefinePlugin({
|
||||||
loader: 'raw-loader'
|
'process.env': {
|
||||||
},
|
'PRODUCTION': production,
|
||||||
],
|
'NEWS_URI': production ? `"${process.env.NEWS_URI}"` : '"http://localhost:3100"',
|
||||||
},
|
'AUTH_URI': production ? `"${process.env.AUTH_URI}"` : '"http://localhost:3200"',
|
||||||
]
|
'CHAT_URI': production ? `"${process.env.CHAT_URI}"` : '"http://localhost:3300"',
|
||||||
},
|
}
|
||||||
plugins: [
|
}),
|
||||||
new DefinePlugin({
|
new CleanWebpackPlugin({
|
||||||
'process.env': {
|
cleanOnceBeforeBuildPatterns: ['*', '!content*']
|
||||||
'PRODUCTION': production,
|
}),
|
||||||
'NEWS_URI': production ? `"${process.env.NEWS_URI}"` : '"https://dev-news.krgamestudios.com"',
|
new HtmlWebpackPlugin({
|
||||||
'AUTH_URI': production ? `"${process.env.AUTH_URI}"` : '"https://dev-auth.krgamestudios.com"',
|
template: './client/template.html',
|
||||||
'CHAT_URI': production ? `"${process.env.CHAT_URI}"` : '"https://dev-chat.krgamestudios.com"',
|
minify: {
|
||||||
}
|
collapseWhitespace: production,
|
||||||
}),
|
removeComments: production,
|
||||||
new CleanWebpackPlugin({
|
removeAttributeQuotes: production
|
||||||
cleanOnceBeforeBuildPatterns: ['*', '!content*']
|
}
|
||||||
}),
|
}),
|
||||||
new HtmlWebpackPlugin({
|
new CompressionPlugin({
|
||||||
template: './client/template.html',
|
filename: "[path][base].gz[query]",
|
||||||
minify: {
|
algorithm: "gzip",
|
||||||
collapseWhitespace: production,
|
test: /\.js$|\.css$/,
|
||||||
removeComments: production,
|
minRatio: 0.8
|
||||||
removeAttributeQuotes: production
|
}),
|
||||||
}
|
new BundleAnalyzerPlugin({
|
||||||
}),
|
analyzerMode: analyze ? 'server' : 'disabled'
|
||||||
new BundleAnalyzerPlugin({
|
})
|
||||||
analyzerMode: analyzer ? 'server' : 'disabled'
|
],
|
||||||
})
|
devServer: {
|
||||||
],
|
hot: true,
|
||||||
devServer: {
|
host: 'localhost',
|
||||||
contentBase: path.resolve(__dirname, 'public'),
|
port: 3001,
|
||||||
compress: true,
|
client: {
|
||||||
port: 3001,
|
overlay: {
|
||||||
proxy: {
|
errors: true,
|
||||||
'/api/': 'http://localhost:3000/'
|
warnings: true,
|
||||||
},
|
},
|
||||||
overlay: {
|
},
|
||||||
errors: true
|
|
||||||
},
|
watchFiles: {
|
||||||
stats: {
|
options: {
|
||||||
colors: true,
|
ignored: ['node_modules/**']
|
||||||
hash: false,
|
}
|
||||||
version: false,
|
},
|
||||||
timings: false,
|
|
||||||
assets: false,
|
proxy: [
|
||||||
chunks: false,
|
{
|
||||||
modules: false,
|
context: ['/api'],
|
||||||
reasons: false,
|
target: 'http://localhost:3000',
|
||||||
children: false,
|
}
|
||||||
source: false,
|
],
|
||||||
errors: true,
|
|
||||||
errorDetails: false,
|
static: '/public',
|
||||||
warnings: true,
|
|
||||||
publicPath: false
|
historyApiFallback: true
|
||||||
},
|
}
|
||||||
host: '0.0.0.0',
|
}
|
||||||
disableHostCheck: true,
|
};
|
||||||
clientLogLevel: 'silent',
|
|
||||||
historyApiFallback: true,
|
|
||||||
hot: true,
|
|
||||||
injectHot: true
|
|
||||||
},
|
|
||||||
watchOptions: {
|
|
||||||
ignored: /(node_modules)/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user