Remove context crap (breaks nojs support) but keep other changes

develop
Thomas Lynch 1 year ago
parent d2e2c8b07f
commit 76f4cf527b
  1. 2
      api.js
  2. 8
      components/ClusterRow.js
  3. 10
      components/MapRow.js
  4. 1
      controllers/maps.js
  5. 8
      gulpfile.js
  6. 16788
      package-lock.json
  7. 19
      package.json
  8. 2
      pages/_document.js
  9. 14
      pages/account.js
  10. 15
      pages/clusters.js
  11. 14
      pages/domains.js
  12. 7
      pages/login.js
  13. 19
      pages/map/[name].js
  14. 6
      pages/register.js
  15. 2
      router.js
  16. 10
      util.js

@ -108,7 +108,7 @@ export async function ApiCall(route, method='get', body, dispatch, errorCallback
errorCallback(response.error);
return;
}
dispatch({ type: 'state', payload: response });
dispatch(response);
} else {
errorCallback('An error occurred');
}

@ -1,10 +1,4 @@
import { useContext } from 'react';
import { GlobalContext } from '../providers/GlobalProvider.js';
export default function ClusterRow({ i, cluster, setCluster, deleteCluster }) {
const [state] = useContext(GlobalContext);
const { user, csrf } = state;
export default function ClusterRow({ i, cluster, setCluster, deleteCluster, csrf, user }) {
return (
<tr className="align-middle">

@ -1,12 +1,6 @@
import Link from 'next/link';
import { useContext } from 'react';
import { GlobalContext } from '../providers/GlobalProvider.js';
export default function MapRow({ row, onDeleteSubmit, name, csrf, showValues, mapValueNames }) {
export default function MapRow({ row, onDeleteSubmit }) {
const [state] = useContext(GlobalContext);
const { user, mapValueNames, mapId, map, csrf, name, showValues } = state;
const [id, key, value] = row.split(' ');
const [_id, key, value] = row.split(' ');
return (
<tr className="align-middle">

@ -53,7 +53,6 @@ exports.mapData = async (req, res, next) => {
name: req.params.name,
showValues,
};
};
exports.mapPage = async (app, req, res, next) => {

@ -15,8 +15,8 @@ async function reset() {
.insertOne({
_id: 'admin',
passwordHash: passwordHash,
domains: ['fatchan.net'],
clusters: ['tcp://23.95.43.254:2000,tcp://142.202.188.239:2000'],
domains: ['localhost'],
clusters: ['tcp://127.0.0.1:2000'],
activeCluster: 0,
balance: 0,
});
@ -27,8 +27,8 @@ async function reset() {
}, {
$set: {
passwordHash,
domains: ['fatchan.net'],
clusters: ['tcp://23.95.43.254:2000,tcp://142.202.188.239:2000'],
domains: ['localhost'],
clusters: ['tcp://127.0.0.1:2000'],
activeCluster: 0,
}
});

16788
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -7,30 +7,31 @@
"dev": "node server.js",
"build": "next build",
"lint": "next lint",
"next": "next build",
"start": "node_modules/gulp/bin/gulp.js; NODE_ENV=production node server.js"
},
"keywords": [],
"author": "Thomas Lynch (fatchan) <tom@69420.me>",
"license": "AGPL-3.0-only",
"dependencies": {
"@fatchan/haproxy-sdk": "^1.0.5",
"bcrypt": "^5.0.1",
"@fatchan/haproxy-sdk": "^1.0.6",
"bcrypt": "^5.1.0",
"body-parser": "^1.20.0",
"bootstrap": "^5.1.3",
"bootstrap": "^5.2.3",
"connect-mongo": "^4.6.0",
"cookie-parser": "^1.4.6",
"csurf": "^1.11.0",
"dotenv": "^16.0.0",
"express": "^4.18.1",
"express-session": "^1.17.2",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"express-session": "^1.17.3",
"fs-extra": "^10.1.0",
"gulp": "^4.0.2",
"ip6addr": "^0.2.5",
"next": "^12.1.6",
"next": "^12.3.4",
"nprogress": "^0.2.0",
"react": "^18.1.0",
"react": "^18.2.0",
"react-content-loader": "^6.2.0",
"react-dom": "^18.1.0"
"react-dom": "^18.2.0"
},
"devDependencies": {
"eslint": "8.15.0",

@ -7,7 +7,7 @@ export default function Document() {
<body>
<Main />
<NextScript className="d-flex flex-column" />
<style global="true">
<style>
{`
html, body, #__next {
min-height: 100vh;

@ -1,4 +1,4 @@
import React, { useState, useContext, useEffect, useMemo } from 'react';
import React, { useState, useEffect, useMemo } from 'react';
import Head from 'next/head';
import Link from 'next/link';
import MapLink from '../components/MapLink.js';
@ -6,22 +6,19 @@ import LoadingPlaceholder from '../components/LoadingPlaceholder.js';
import ErrorAlert from '../components/ErrorAlert.js';
import * as API from '../api.js';
import { useRouter } from 'next/router';
import { GlobalContext } from '../providers/GlobalProvider.js';
const Account = (props) => {
const router = useRouter();
const [state, dispatch] = useContext(GlobalContext);
const [state, dispatch] = useState(props);
const [error, setError] = useState();
// Set into context from props (From getServerSideProps), else make API call
useEffect(() => {
if (props.maps != null) {
dispatch({ type: 'state', payload: props });
} else {
if (!state.user) {
API.getAccount(dispatch, setError, router);
}
}, [dispatch, props, router]);
}, [state.user, router]);
const loadingSection = useMemo(() => {
return (
@ -33,10 +30,9 @@ const Account = (props) => {
let innerData;
//TODO: when coming from loaded map after refresh, will already have some data, so we should partially populate page
if (state.maps != null) {
const { user, maps, acls, globalAcl, csrf } = state;
const { user, maps, globalAcl, csrf } = state;
// isAdmin for showing global override option
const isAdmin = user.username === 'admin';

@ -1,27 +1,22 @@
import React, { useState, useContext, useEffect } from 'react';
import React, { useState, useEffect } from 'react';
import Head from 'next/head';
import Link from 'next/link';
import BackButton from '../components/BackButton.js'
import ErrorAlert from '../components/ErrorAlert.js';
import ClusterRow from '../components/ClusterRow.js';
import * as API from '../api.js'
import { useRouter } from 'next/router';
import { GlobalContext } from '../providers/GlobalProvider.js';
export default function Clusters(props) {
const router = useRouter();
const [state, dispatch] = useContext(GlobalContext);
const [state, dispatch] = useState(props);
const [error, setError] = useState();
// Set into context from props (From getServerSideProps), else make API call
useEffect(() => {
if (props.user != null) {
dispatch({ type: 'state', payload: props });
} else {
if (!state.user) {
API.getClusters(dispatch, setError, router);
}
}, [dispatch, props, router]);
}, [state.user, router]);
if (!state.user) {
return (
@ -56,6 +51,8 @@ export default function Clusters(props) {
i={i}
key={cluster}
cluster={cluster}
csrf={csrf}
user={user}
setCluster={setCluster}
deleteCluster={deleteCluster}
/>));

@ -1,26 +1,21 @@
import React, { useState, useContext, useEffect } from 'react';
import React, { useState, useEffect } from 'react';
import Head from 'next/head';
import Link from 'next/link';
import BackButton from '../components/BackButton.js';
import LoadingPlaceholder from '../components/LoadingPlaceholder.js';
import ErrorAlert from '../components/ErrorAlert.js';
import * as API from '../api.js'
import { useRouter } from 'next/router';
import { GlobalContext } from '../providers/GlobalProvider.js';
export default function Domains(props) {
const router = useRouter();
const [state, dispatch] = useContext(GlobalContext);
const [state, dispatch] = useState(props);
const [error, setError] = useState();
useEffect(() => {
if (props.user != null) {
dispatch({ type: 'state', payload: props });
} else {
if (!state.user) {
API.getDomains(dispatch, setError, router);
}
}, [dispatch, props, router]);
}, [state.user, router]);
if (!state.user) {
return (
@ -65,6 +60,7 @@ export default function Domains(props) {
return (
<>
<Head>
<title>Domains</title>
</Head>

@ -2,14 +2,11 @@ import Head from 'next/head';
import { useRouter } from 'next/router';
import * as API from '../api.js'
import ErrorAlert from '../components/ErrorAlert.js';
import { useState, useContext } from 'react';
import { GlobalContext } from '../providers/GlobalProvider.js';
import { useState } from 'react';
const Login = () => {
const router = useRouter();
const [state, dispatch] = useContext(GlobalContext);
const [error, setError] = useState();
async function login(e) {
@ -17,7 +14,7 @@ const Login = () => {
await API.login({
username: e.target.username.value,
password: e.target.password.value,
}, dispatch, setError, router);
}, null, setError, router);
}
return (

@ -1,29 +1,24 @@
import { useRouter } from "next/router";
import React, { useState, useContext, useEffect } from 'react';
import React, { useState, useEffect } from 'react';
import Head from 'next/head';
import Link from 'next/link';
import MapRow from '../../components/MapRow.js';
import BackButton from '../../components/BackButton.js';
import ErrorAlert from '../../components/ErrorAlert.js';
import * as API from '../../api.js';
import { GlobalContext } from '../../providers/GlobalProvider.js';
const MapPage = (props) => {
const router = useRouter();
const { name: mapName } = router.query;
const [state, dispatch] = useContext(GlobalContext);
const [state, dispatch] = useState(props);
const [error, setError] = useState();
const changedMap = state.mapId?.name != mapName;
useEffect(() => {
if (props.map != null) {
dispatch({ type: 'state', payload: props });
} else {
//TODO: eventually, keep all visited maps in the context and refresh on load like e.g. clusters
if (!state.map) {
API.getMap(mapName, dispatch, setError, router);
}
}, [changedMap, mapName, dispatch, props, router]);
}, [state.map, mapName, router]);
if (state.map == null || changedMap) {
return (
@ -34,7 +29,7 @@ const MapPage = (props) => {
);
}
const { user, mapValueNames, mapId, map, csrf, name, showValues } = state;
const { user, mapValueNames, mapId, map, csrf, showValues } = state;
async function addToMap(e) {
e.preventDefault();
@ -54,6 +49,10 @@ const MapPage = (props) => {
<MapRow
key={i}
row={row}
name={mapId.name}
csrf={csrf}
showValues={showValues}
mapValueNames={mapValueNames}
onDeleteSubmit={deleteFromMap}
/>
)

@ -2,13 +2,11 @@ import Head from 'next/head';
import { useRouter } from 'next/router';
import * as API from '../api.js'
import ErrorAlert from '../components/ErrorAlert.js';
import { useState, useContext } from 'react';
import { GlobalContext } from '../providers/GlobalProvider.js';
import { useState } from 'react';
const Register = () => {
const router = useRouter();
const [state, dispatch] = useContext(GlobalContext);
const [error, setError] = useState();
async function register(e) {
@ -17,7 +15,7 @@ const Register = () => {
username: e.target.username.value,
password: e.target.password.value,
rpasword: e.target.repeat_password.value,
}, dispatch, setError, router);
}, null, setError, router);
router.push('/login');
}

@ -17,7 +17,7 @@ const testRouter = (server, app) => {
rolling: true,
cookie: {
httpOnly: true,
secure: false, //!dev, //TODO: check https
secure: !dev, //TODO: check https
sameSite: 'strict',
maxAge: 1000 * 60 * 60 * 24 * 7, //week
}

@ -32,11 +32,11 @@ const fMap = {
columnNames: ['Domain', ''],
},
/*[process.env.BACKENDS_MAP_NAME]: {
[process.env.BACKENDS_MAP_NAME]: {
fname: 'Domain Backend Mappings',
description: 'Which internal server haproxy uses for domains',
columnNames: ['Domain', 'Server Name'],
},*/
},
};
@ -54,7 +54,7 @@ module.exports = {
},
extractMap: (item) => {
const match = item.match(/(?<index>\d+) \(\/etc\/haproxy\/(?<name>.+).map\)(?:.+entry_cnt=(?<count>\d+)$)?/);
const match = item.match(/(?<index>\d+) \(\/etc\/haproxy\/map\/(?<name>.+).map\)(?:.+entry_cnt=(?<count>\d+)$)?/);
if (match && match.groups) {
return {
...match.groups,
@ -63,7 +63,7 @@ module.exports = {
}
},
getMapId: async (haproxy, name) => {
getMapId: (haproxy, name) => {
return haproxy.showMap()
.then(list => {
return list
@ -81,7 +81,7 @@ module.exports = {
return haproxy.delMap(mapId.index, value);
},
dynamicResponse: async(req, res, code, data) => {
dynamicResponse: (req, res, code, data) => {
const isRedirect = code === 302;
if (req.headers && req.headers['content-type'] === 'application/json') {
return res

Loading…
Cancel
Save