Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 |
@@ -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
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ 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.
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ 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
|
cd MERN-template
|
||||||
node configure-script.js
|
node configure-script.js
|
||||||
docker-compose up --build
|
docker compose up --build
|
||||||
```
|
```
|
||||||
|
|
||||||
# Setup Development
|
# Setup Development
|
||||||
@@ -56,6 +56,7 @@ 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
|
- 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
|
||||||
|
|||||||
+9
-7
@@ -2,14 +2,16 @@
|
|||||||
import 'regenerator-runtime/runtime';
|
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 './pages/app';
|
import App from './pages/app';
|
||||||
import TokenProvider from './pages/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,5 +1,5 @@
|
|||||||
import React, { useEffect, useContext, useRef } from 'react';
|
import React, { useEffect, useContext, useRef } from 'react';
|
||||||
import { Link, Redirect } from 'react-router-dom';
|
import { Link, Navigate } from 'react-router-dom';
|
||||||
|
|
||||||
import ApplyToBody from '../utilities/apply-to-body';
|
import ApplyToBody from '../utilities/apply-to-body';
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ const Account = props => {
|
|||||||
|
|
||||||
//misplaced?
|
//misplaced?
|
||||||
if (!authTokens.accessToken) {
|
if (!authTokens.accessToken) {
|
||||||
return <Redirect to='/' />;
|
return <Navigate to='/' />;
|
||||||
}
|
}
|
||||||
|
|
||||||
//refs
|
//refs
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useContext, useRef } from 'react';
|
import React, { useContext, useRef } from 'react';
|
||||||
import { Link, Redirect } from 'react-router-dom';
|
import { Link, Navigate } from 'react-router-dom';
|
||||||
|
|
||||||
import ApplyToBody from '../utilities/apply-to-body';
|
import ApplyToBody from '../utilities/apply-to-body';
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ const Login = props => {
|
|||||||
|
|
||||||
//misplaced?
|
//misplaced?
|
||||||
if (authTokens.accessToken) {
|
if (authTokens.accessToken) {
|
||||||
return <Redirect to='/' />;
|
return <Navigate to='/' />;
|
||||||
}
|
}
|
||||||
|
|
||||||
//refs
|
//refs
|
||||||
@@ -40,7 +40,7 @@ const Login = props => {
|
|||||||
if (accessToken) {
|
if (accessToken) {
|
||||||
authTokens.setAccessToken(accessToken);
|
authTokens.setAccessToken(accessToken);
|
||||||
|
|
||||||
props.history.push('/');
|
return <Navigate to='/' />;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}>
|
}>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useContext, useRef } from 'react';
|
import React, { useContext, useRef } from 'react';
|
||||||
import { Link, Redirect } from 'react-router-dom';
|
import { Link, useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
import ApplyToBody from '../utilities/apply-to-body';
|
import ApplyToBody from '../utilities/apply-to-body';
|
||||||
|
|
||||||
@@ -9,12 +9,15 @@ import { TokenContext } from '../utilities/token-provider';
|
|||||||
const validateEmail = require('../../../common/utilities/validate-email');
|
const validateEmail = require('../../../common/utilities/validate-email');
|
||||||
|
|
||||||
const Recover = props => {
|
const Recover = props => {
|
||||||
|
//history
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
//context
|
//context
|
||||||
const authTokens = useContext(TokenContext);
|
const authTokens = useContext(TokenContext);
|
||||||
|
|
||||||
//misplaced?
|
//misplaced?
|
||||||
if (authTokens.accessToken) {
|
if (authTokens.accessToken) {
|
||||||
return <Redirect to='/' />;
|
navigate("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
//refs
|
//refs
|
||||||
@@ -39,7 +42,7 @@ const Recover = props => {
|
|||||||
|
|
||||||
//redirect
|
//redirect
|
||||||
if (redirect) {
|
if (redirect) {
|
||||||
props.history.push('/');
|
navigate("/");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}>
|
}>
|
||||||
|
|||||||
@@ -1,21 +1,23 @@
|
|||||||
import React, { useContext, useRef } from 'react';
|
import React, { useContext, useRef } from 'react';
|
||||||
import { Link, Redirect } from 'react-router-dom';
|
import { Link, useNavigate, useSearchParams } from 'react-router-dom';
|
||||||
import queryString from 'query-string';
|
|
||||||
|
|
||||||
import ApplyToBody from '../utilities/apply-to-body';
|
import ApplyToBody from '../utilities/apply-to-body';
|
||||||
|
|
||||||
import { TokenContext } from '../utilities/token-provider';
|
import { TokenContext } from '../utilities/token-provider';
|
||||||
|
|
||||||
const Reset = props => {
|
const Reset = props => {
|
||||||
|
//params
|
||||||
|
const [params, setParams] = useSearchParams(); //the URLSearchParams API
|
||||||
|
|
||||||
|
//history
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
//context
|
//context
|
||||||
const authTokens = useContext(TokenContext);
|
const authTokens = useContext(TokenContext);
|
||||||
|
|
||||||
//query
|
|
||||||
const query = queryString.parse(props.location.search);
|
|
||||||
|
|
||||||
//misplaced?
|
//misplaced?
|
||||||
if (authTokens.accessToken || !query.email || !query.token) {
|
if (authTokens.accessToken || !params.has('email') || !params.has('token')) {
|
||||||
return <Redirect to='/' />;
|
navigate("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
//refs
|
//refs
|
||||||
@@ -31,7 +33,7 @@ const Reset = props => {
|
|||||||
<h1 className='text centered'>Reset Password</h1>
|
<h1 className='text centered'>Reset Password</h1>
|
||||||
<form className='constrained' onSubmit={async evt => {
|
<form className='constrained' onSubmit={async evt => {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
const [err, redirect] = await update(passwordRef.current.value, retypeRef.current.value, query);
|
const [err, redirect] = await update(passwordRef.current.value, retypeRef.current.value, params);
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
alert(err);
|
alert(err);
|
||||||
@@ -42,7 +44,7 @@ const Reset = props => {
|
|||||||
|
|
||||||
//redirect
|
//redirect
|
||||||
if (redirect) {
|
if (redirect) {
|
||||||
props.history.push('/');
|
navigate("/");
|
||||||
}
|
}
|
||||||
}}>
|
}}>
|
||||||
<input type='password' name='password' placeholder='New Password' ref={passwordRef} />
|
<input type='password' name='password' placeholder='New Password' ref={passwordRef} />
|
||||||
@@ -56,7 +58,7 @@ const Reset = props => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const update = async (password, retype, query) => {
|
const update = async (password, retype, params) => {
|
||||||
if (password != retype) {
|
if (password != retype) {
|
||||||
return ['Passwords do not match'];
|
return ['Passwords do not match'];
|
||||||
}
|
}
|
||||||
@@ -65,7 +67,7 @@ const update = async (password, retype, query) => {
|
|||||||
return ['Password is too short'];
|
return ['Password is too short'];
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await fetch(`${process.env.AUTH_URI}/auth/reset?email=${query.email}&token=${query.token}`, {
|
const result = await fetch(`${process.env.AUTH_URI}/auth/reset?email=${params.get('email')}&token=${params.get('token')}`, {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useContext, useRef } from 'react';
|
import React, { useContext, useRef } from 'react';
|
||||||
import { Link, Redirect } from 'react-router-dom';
|
import { Link, useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
import ApplyToBody from '../utilities/apply-to-body';
|
import ApplyToBody from '../utilities/apply-to-body';
|
||||||
|
|
||||||
@@ -10,12 +10,15 @@ const validateEmail = require('../../../common/utilities/validate-email');
|
|||||||
const validateUsername = require('../../../common/utilities/validate-username');
|
const validateUsername = require('../../../common/utilities/validate-username');
|
||||||
|
|
||||||
const Signup = props => {
|
const Signup = props => {
|
||||||
|
//history
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
//context
|
//context
|
||||||
const authTokens = useContext(TokenContext);
|
const authTokens = useContext(TokenContext);
|
||||||
|
|
||||||
//misplaced?
|
//misplaced?
|
||||||
if (authTokens.accessToken) {
|
if (authTokens.accessToken) {
|
||||||
return <Redirect to='/' />;
|
navigate("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
//refs
|
//refs
|
||||||
@@ -44,7 +47,7 @@ const Signup = props => {
|
|||||||
|
|
||||||
//redirect
|
//redirect
|
||||||
if (redirect) {
|
if (redirect) {
|
||||||
props.history.push('/');
|
navigate("/");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}>
|
}>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useContext } from 'react';
|
import React, { useContext } from 'react';
|
||||||
import { Link, Redirect } from 'react-router-dom';
|
import { Link, Navigate } from 'react-router-dom';
|
||||||
|
|
||||||
import ApplyToBody from '../utilities/apply-to-body';
|
import ApplyToBody from '../utilities/apply-to-body';
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ const Admin = props => {
|
|||||||
|
|
||||||
//misplaced? (admin only)
|
//misplaced? (admin only)
|
||||||
if (!authTokens.accessToken || !authTokens.getPayload().admin) {
|
if (!authTokens.accessToken || !authTokens.getPayload().admin) {
|
||||||
return <Redirect to='/' />;
|
return <Navigate to='/' />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useContext } from 'react';
|
import React, { useContext } from 'react';
|
||||||
import { Link, Redirect } from 'react-router-dom';
|
import { Link, Navigate } from 'react-router-dom';
|
||||||
|
|
||||||
import ApplyToBody from '../utilities/apply-to-body';
|
import ApplyToBody from '../utilities/apply-to-body';
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ const Mod = props => {
|
|||||||
|
|
||||||
//misplaced? (admin only)
|
//misplaced? (admin only)
|
||||||
if (!authTokens.accessToken || !(authTokens.getPayload().admin || authTokens.getPayload().mod)) {
|
if (!authTokens.accessToken || !(authTokens.getPayload().admin || authTokens.getPayload().mod)) {
|
||||||
return <Redirect to='/' />;
|
return <Navigate to='/' />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -7,16 +7,13 @@ const ChatReports = props => {
|
|||||||
|
|
||||||
const authTokens = useContext(TokenContext);
|
const authTokens = useContext(TokenContext);
|
||||||
|
|
||||||
useEffect(async () => {
|
useEffect(() => {
|
||||||
const result = await authTokens.tokenFetch(`${process.env.CHAT_URI}/admin/reports`);
|
authTokens.tokenFetch(`${process.env.CHAT_URI}/admin/reports`)
|
||||||
|
.then(res => res.json())
|
||||||
if (!result.ok) {
|
.then(json => {
|
||||||
const err = `${result.status}: ${await result.text()}`;
|
setReports(json);
|
||||||
console.log(err);
|
})
|
||||||
alert(err);
|
;
|
||||||
} else {
|
|
||||||
setReports(await result.json());
|
|
||||||
}
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -17,16 +17,13 @@ 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`)
|
||||||
|
.then(res => res.json())
|
||||||
if (!result.ok) {
|
.then(json => {
|
||||||
const err = `${result.status}: ${await result.text()}`;
|
setArticles(json)
|
||||||
console.log(err);
|
})
|
||||||
alert(err);
|
;
|
||||||
} else {
|
|
||||||
setArticles(await result.json());
|
|
||||||
}
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
+34
-21
@@ -1,11 +1,8 @@
|
|||||||
//react
|
//react
|
||||||
import React, { useContext } from 'react';
|
import React, { useContext, Suspense, lazy } from 'react';
|
||||||
import { BrowserRouter, Switch } from 'react-router-dom';
|
import { BrowserRouter, Routes, Route } from 'react-router-dom';
|
||||||
import { TokenContext } from './utilities/token-provider';
|
import { TokenContext } from './utilities/token-provider';
|
||||||
|
|
||||||
//library components
|
|
||||||
import LazyRoute from './utilities/lazy-route';
|
|
||||||
|
|
||||||
//styling
|
//styling
|
||||||
import '../styles/styles.css';
|
import '../styles/styles.css';
|
||||||
|
|
||||||
@@ -13,33 +10,49 @@ import '../styles/styles.css';
|
|||||||
import Footer from './panels/footer';
|
import Footer from './panels/footer';
|
||||||
import PopupChat from './panels/popup-chat';
|
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 App = props => {
|
||||||
const authTokens = useContext(TokenContext);
|
const authTokens = useContext(TokenContext);
|
||||||
|
|
||||||
//default render
|
//default render
|
||||||
return (
|
return (
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
<Switch>
|
<Suspense>
|
||||||
<LazyRoute exact path='/' component={() => import('./homepage')} />
|
<Routes>
|
||||||
|
<Route exact path='/' element={<Homepage />} />
|
||||||
|
|
||||||
<LazyRoute path='/signup' component={() => import('./accounts/signup')} />
|
<Route path='/signup' element={<Signup />} />
|
||||||
<LazyRoute path='/login' component={() => import('./accounts/login')} />
|
<Route path='/login' element={<Login />} />
|
||||||
<LazyRoute path='/account' component={() => import('./accounts/account')} />
|
<Route path='/account' element={<Account />} />
|
||||||
<LazyRoute path='/dashboard' component={() => import('./dashboard')} />
|
<Route path='/dashboard' element={<Dashboard />} />
|
||||||
|
|
||||||
<LazyRoute path='/recover' component={() => import('./accounts/recover')} />
|
<Route path='/recover' element={<Recover />} />
|
||||||
<LazyRoute path='/reset' component={() => import('./accounts/reset')} />
|
<Route path='/reset' element={<Reset />} />
|
||||||
|
|
||||||
<LazyRoute path='/admin' component={() => import('./administration/admin')} />
|
<Route path='/admin' element={<Admin />} />
|
||||||
<LazyRoute path='/mod' component={() => import('./administration/mod')} />
|
<Route path='/mod' element={<Mod />} />
|
||||||
|
|
||||||
<LazyRoute path='/privacypolicy' component={() => import('./static/privacy-policy')} />
|
<Route path='/privacypolicy' element={<PrivacyPolicy />} />
|
||||||
<LazyRoute path='/credits' component={() => import('./static/credits')} />
|
<Route path='/credits' element={<Credits />} />
|
||||||
|
|
||||||
<LazyRoute path='*' component={() => import('./not-found')} />
|
<Route path='*' element={<NotFound />} />
|
||||||
</Switch>
|
</Routes>
|
||||||
{ authTokens.accessToken ? <PopupChat /> : <></> }
|
</Suspense>
|
||||||
<Footer />
|
{ authTokens.accessToken ? <PopupChat /> : <></> }
|
||||||
|
<Footer />
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useContext } from 'react';
|
import React, { useContext } from 'react';
|
||||||
import { Link, Redirect } from 'react-router-dom';
|
import { Link, Navigate } from 'react-router-dom';
|
||||||
|
|
||||||
import ApplyToBody from './utilities/apply-to-body';
|
import ApplyToBody from './utilities/apply-to-body';
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ const Dashboard = props => {
|
|||||||
|
|
||||||
//misplaced?
|
//misplaced?
|
||||||
if (!authTokens.accessToken) {
|
if (!authTokens.accessToken) {
|
||||||
return <Redirect to='/' />;
|
return <Navigate to='/' />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useContext } from 'react';
|
import React, { useContext } from 'react';
|
||||||
import { Link, Redirect } from 'react-router-dom';
|
import { Link, Navigate } from 'react-router-dom';
|
||||||
|
|
||||||
import ApplyToBody from './utilities/apply-to-body';
|
import ApplyToBody from './utilities/apply-to-body';
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ const HomePage = props => {
|
|||||||
|
|
||||||
//misplaced?
|
//misplaced?
|
||||||
if (authTokens.accessToken) {
|
if (authTokens.accessToken) {
|
||||||
return <Redirect to='/dashboard' />;
|
return <Navigate to='/dashboard' />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ const Break = () => {
|
|||||||
const Footer = () => {
|
const Footer = () => {
|
||||||
return (
|
return (
|
||||||
<footer>
|
<footer>
|
||||||
<p className='text centered'>© <a href='https://krgamestudios.com'>KR Game Studios</a> 2020-2022<Break /><Link to='/privacypolicy'>Privacy Policy</Link><Break /><Link to='/credits'>Credits</Link></p>
|
<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>
|
</footer>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ const NewsFeed = props => {
|
|||||||
<div className='panel'>
|
<div className='panel'>
|
||||||
<h1 className='text centered'>News Feed</h1>
|
<h1 className='text centered'>News Feed</h1>
|
||||||
{articles.map((article, index) => {
|
{articles.map((article, index) => {
|
||||||
console.log(article)
|
|
||||||
return (
|
return (
|
||||||
<div key={index} className='panel'>
|
<div key={index} className='panel'>
|
||||||
<hr />
|
<hr />
|
||||||
|
|||||||
@@ -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,5 +1,5 @@
|
|||||||
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();
|
||||||
|
|
||||||
@@ -9,6 +9,12 @@ const TokenProvider = props => {
|
|||||||
//state to be used
|
//state to be used
|
||||||
const [accessToken, setAccessToken] = useState('');
|
const [accessToken, setAccessToken] = useState('');
|
||||||
|
|
||||||
|
//force a logout under certain conditions
|
||||||
|
const forceLogout = () => {
|
||||||
|
localStorage.removeItem("accessToken");
|
||||||
|
setAccessToken("");
|
||||||
|
};
|
||||||
|
|
||||||
//make the access token persist between reloads
|
//make the access token persist between reloads
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setAccessToken(localStorage.getItem("accessToken") || '');
|
setAccessToken(localStorage.getItem("accessToken") || '');
|
||||||
@@ -25,7 +31,7 @@ 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) {
|
||||||
//BUGFIX: if logging out, just skip over the refresh token
|
//BUGFIX: if logging out, just skip over the refresh token
|
||||||
@@ -42,11 +48,17 @@ const TokenProvider = props => {
|
|||||||
//ping the auth server for a new access token
|
//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: {
|
||||||
|
'Authorization': `Bearer ${bearer}`
|
||||||
|
},
|
||||||
credentials: 'include'
|
credentials: 'include'
|
||||||
});
|
});
|
||||||
|
|
||||||
//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()}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,18 +82,27 @@ const TokenProvider = props => {
|
|||||||
|
|
||||||
//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: {
|
||||||
|
'Authorization': `Bearer ${bearer}`
|
||||||
|
},
|
||||||
credentials: 'include'
|
credentials: 'include'
|
||||||
});
|
});
|
||||||
|
|
||||||
//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()}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +119,7 @@ const TokenProvider = props => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TokenContext.Provider value={{ accessToken, setAccessToken, tokenFetch, tokenCallback, getPayload: () => decode(accessToken) }}>
|
<TokenContext.Provider value={{ accessToken, setAccessToken, tokenFetch, tokenCallback, getPayload: () => jwtDecode(accessToken) }}>
|
||||||
{props.children}
|
{props.children}
|
||||||
</TokenContext.Provider>
|
</TokenContext.Provider>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
+122
-27
@@ -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
|
||||||
@@ -49,7 +49,7 @@ See https://github.com/krgamestudios/MERN-template/wiki for help.
|
|||||||
//determine local computer address for mac user vs everyone else
|
//determine local computer address for mac user vs everyone else
|
||||||
let macUser = '';
|
let macUser = '';
|
||||||
while (macUser.toLowerCase() !== 'yes' && macUser.toLowerCase() !== 'no') {
|
while (macUser.toLowerCase() !== 'yes' && macUser.toLowerCase() !== 'no') {
|
||||||
macUser = await question('Will the MERN Template be running locally on a MacOS system? (yes or 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 ? 'localhost' : '%';
|
const localAddress = macUser ? 'localhost' : '%';
|
||||||
@@ -58,13 +58,48 @@ See https://github.com/krgamestudios/MERN-template/wiki for help.
|
|||||||
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');
|
||||||
|
|
||||||
|
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);
|
|
||||||
|
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');
|
const newsDBPass = await question('News DB Password', 'venusaur');
|
||||||
|
|
||||||
//auth configuration
|
//auth configuration
|
||||||
@@ -72,7 +107,25 @@ See https://github.com/krgamestudios/MERN-template/wiki for help.
|
|||||||
const authWebAddress = await question('Auth Web Address', `${authName}.${projectWebAddress}`);
|
const authWebAddress = await question('Auth Web Address', `${authName}.${projectWebAddress}`);
|
||||||
const authPostValidationHookArray = await question('Auth Post Validation Hook Array', '');
|
const authPostValidationHookArray = await question('Auth Post Validation Hook Array', '');
|
||||||
const authResetAddress = await question('Auth Reset Addr', `${projectWebAddress}/reset`);
|
const authResetAddress = await question('Auth Reset Addr', `${projectWebAddress}/reset`);
|
||||||
const authDBUser = await question('Auth DB Username', authName);
|
|
||||||
|
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 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');
|
||||||
@@ -83,7 +136,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
|
||||||
@@ -99,11 +170,14 @@ 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}@${authWebAddress}`);
|
||||||
@@ -113,18 +187,17 @@ See https://github.com/krgamestudios/MERN-template/wiki for help.
|
|||||||
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}\`)
|
||||||
@@ -134,7 +207,8 @@ services:
|
|||||||
- traefik.http.services.${projectName}service.loadbalancer.server.port=${projectPort}
|
- traefik.http.services.${projectName}service.loadbalancer.server.port=${projectPort}
|
||||||
environment:
|
environment:
|
||||||
- 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}
|
||||||
@@ -143,10 +217,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}:
|
||||||
@@ -162,17 +239,21 @@ services:
|
|||||||
- traefik.http.services.${newsName}service.loadbalancer.server.port=${newsPort}
|
- traefik.http.services.${newsName}service.loadbalancer.server.port=${newsPort}
|
||||||
environment:
|
environment:
|
||||||
- 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}:
|
||||||
@@ -192,7 +273,8 @@ services:
|
|||||||
- HOOK_POST_VALIDATION_ARRAY=${authPostValidationHookArray}
|
- HOOK_POST_VALIDATION_ARRAY=${authPostValidationHookArray}
|
||||||
- WEB_RESET_ADDRESS=${authResetAddress}
|
- 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}
|
||||||
@@ -202,13 +284,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}:
|
||||||
@@ -224,18 +310,23 @@ services:
|
|||||||
- traefik.http.services.${chatName}service.loadbalancer.server.port=${chatPort}
|
- traefik.http.services.${chatName}service.loadbalancer.server.port=${chatPort}
|
||||||
environment:
|
environment:
|
||||||
- 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
|
||||||
@@ -244,11 +335,13 @@ 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
|
||||||
@@ -269,6 +362,8 @@ services:
|
|||||||
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
|
||||||
|
|
||||||
@@ -278,7 +373,7 @@ networks:
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
const dockerfile = `
|
const dockerfile = `
|
||||||
FROM node:16
|
FROM node:22-bookworm-slim
|
||||||
WORKDIR "/app"
|
WORKDIR "/app"
|
||||||
COPY . /app
|
COPY . /app
|
||||||
RUN mkdir /app/public
|
RUN mkdir /app/public
|
||||||
|
|||||||
Generated
+3096
-8092
File diff suppressed because it is too large
Load Diff
+29
-31
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "mern-template",
|
"name": "mern-template",
|
||||||
"version": "1.3.0",
|
"version": "1.5.1",
|
||||||
"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": {
|
||||||
@@ -21,42 +21,40 @@
|
|||||||
"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.14.8",
|
"@babel/core": "^7.24.5",
|
||||||
"@babel/preset-env": "^7.14.8",
|
"@babel/preset-env": "^7.24.5",
|
||||||
"@babel/preset-react": "^7.14.5",
|
"@babel/preset-react": "^7.24.1",
|
||||||
"@loadable/component": "^5.15.0",
|
"babel-loader": "^9.1.3",
|
||||||
"babel-loader": "^8.2.2",
|
"clean-webpack-plugin": "^4.0.0",
|
||||||
"clean-webpack-plugin": "^3.0.0",
|
"compression-webpack-plugin": "^11.1.0",
|
||||||
"compression-webpack-plugin": "^8.0.1",
|
"concurrently": "^8.2.2",
|
||||||
"concurrently": "^6.2.0",
|
"css-loader": "^7.1.1",
|
||||||
"css-loader": "^6.2.0",
|
"dateformat": "^5.0.3",
|
||||||
"dateformat": "^4.5.1",
|
"dotenv": "^16.4.5",
|
||||||
"dotenv": "^10.0.0",
|
"express": "^4.19.2",
|
||||||
"express": "^4.17.1",
|
"html-webpack-plugin": "^5.6.0",
|
||||||
"html-webpack-plugin": "^5.3.2",
|
"jwt-decode": "^4.0.0",
|
||||||
"jwt-decode": "^3.1.2",
|
"mariadb": "^3.3.0",
|
||||||
"mariadb": "^2.5.4",
|
"react": "^18.3.1",
|
||||||
"query-string": "^7.0.1",
|
"react-dom": "^18.3.1",
|
||||||
"react": "^17.0.2",
|
"react-router": "^6.3.0",
|
||||||
"react-dom": "^17.0.2",
|
"react-router-dom": "^6.23.0",
|
||||||
"react-router": "^5.2.0",
|
"react-select": "^5.8.0",
|
||||||
"react-router-dom": "^5.2.0",
|
"sequelize": "^6.37.3",
|
||||||
"react-select": "^5.2.1",
|
"socket.io-client": "^4.7.5",
|
||||||
"sequelize": "^6.6.5",
|
"style-loader": "^4.0.0",
|
||||||
"socket.io-client": "^4.1.3",
|
"webpack": "^5.91.0",
|
||||||
"style-loader": "^3.2.1",
|
"webpack-bundle-analyzer": "^4.10.2",
|
||||||
"webpack": "^5.46.0",
|
"webpack-cli": "^5.1.4"
|
||||||
"webpack-bundle-analyzer": "^4.4.2",
|
|
||||||
"webpack-cli": "^4.7.2"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"nodemon": "^2.0.12",
|
"nodemon": "^3.1.0",
|
||||||
"webpack-dev-server": "^4.6.0"
|
"webpack-dev-server": "^5.0.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -42,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 +1,5 @@
|
|||||||
#This file only needs to be run once, during initial development setup
|
#use this while debugging
|
||||||
#This file isnt needed for actual deployment
|
CREATE DATABASE template;
|
||||||
|
CREATE USER 'template'@'%' IDENTIFIED BY 'pikachu';
|
||||||
#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'@'%';
|
GRANT ALL PRIVILEGES ON template.* TO 'template'@'%';
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -91,11 +91,12 @@ module.exports = ({ production, development, local, analyze }) => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
proxy: {
|
proxy: [
|
||||||
'/api': {
|
{
|
||||||
target: 'http://localhost:3000'
|
context: ['/api'],
|
||||||
|
target: 'http://localhost:3000',
|
||||||
}
|
}
|
||||||
},
|
],
|
||||||
|
|
||||||
static: '/public',
|
static: '/public',
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user