diff --git a/client/config.js b/client/config.js deleted file mode 100644 index 57018359e..000000000 --- a/client/config.js +++ /dev/null @@ -1,5 +0,0 @@ -const config = { - env: "development", -} - -export default config diff --git a/client/src/components/App.js b/client/src/components/App.js index 89e535919..706e0fe99 100644 --- a/client/src/components/App.js +++ b/client/src/components/App.js @@ -22,7 +22,7 @@ const App = props => { const getSettings = async () => { const body = (await Fetch.fetchSettings()) setSettings(body) - setZoom(body.startZoom) + setZoom(body.map.startZoom) } useEffect(() => { @@ -36,7 +36,7 @@ const App = props => { {settings && diff --git a/client/src/components/MapTiles.jsx b/client/src/components/MapTiles.jsx index 5476b9c2a..c401f135b 100644 --- a/client/src/components/MapTiles.jsx +++ b/client/src/components/MapTiles.jsx @@ -13,19 +13,19 @@ const MapTiles = ({ map, settings }) => { }) const [position, setPosition] = useState({}) const [selected, setSelected] = useState({ - Gyms: false, - Raids: false, - Pokestops: false, - Quests: false, - Invasions: false, - Spawnpoints: false, - Pokemon: false, - IngressPortals: false, - ScanCells: false, - S2Cells: false, - Weather: false, - ScanAreas: false, - Devices: true + Gyms: settings.map.filters.gyms, + Raids: settings.map.filters.raids, + Pokestops: settings.map.filters.pokestops, + Quests: settings.map.filters.quests, + Invasions: settings.map.filters.invasions, + Spawnpoints: settings.map.filters.spawnpoints, + Pokemon: settings.map.filters.pokemon, + IngressPortals: settings.map.filters.portals, + ScanCells: settings.map.filters.scanCells, + S2Cells: settings.map.filters.submissionCells, + Weather: settings.map.filters.weather, + ScanAreas: settings.map.filters.scanAreas, + Devices: settings.map.filters.devices }) const onMove = useCallback(() => { diff --git a/client/src/services/data/settings.js b/client/src/services/data/settings.js index 2170ccb64..c8a2297e1 100644 --- a/client/src/services/data/settings.js +++ b/client/src/services/data/settings.js @@ -1,6 +1,6 @@ export default async function () { try { - const response = await fetch(`/api/v1/data/settings`) + const response = await fetch(`/settings`) if (!response.ok) { throw new Error(`${response.status} (${response.statusText})`) } diff --git a/server/src/configs/config.example.json b/server/src/configs/config.example.json index c9aff7023..895af6e58 100644 --- a/server/src/configs/config.example.json +++ b/server/src/configs/config.example.json @@ -1,157 +1,169 @@ { - "interface": "0.0.0.0", - "port": 8080, - "title": "MapJS", - "headerTitle": "MapJS - NodeJS Map Replacement", - "locale": "en", - "style": "dark", - "sessionSecret": "98ki^e72~!@#(85o3kXLI*#c9wu5l!Z", - "homepage": { - "enabled": false, - "title": "Welcome to MapJS", - "descriptionLine1": "The best place to find Pokemon, Raids, Quests, and more!", - "descriptionLine2": "Please login or join our Discord for more info...", - "discordInvite": "https://discord.gg/yourInvite" - }, - "map": { - "startLat": 0, - "startLon": 0, - "startZoom": 12, - "minZoom": 10, - "maxZoom": 18 - }, - "areas": { - "test": { "lat": 4.01, "lon": 117.01, "zoom": 15 } + "interface": "0.0.0.0", + "port": 8080, + "title": "MapJS", + "headerTitle": "MapJS - NodeJS Map Replacement", + "locale": "en", + "style": "dark", + "sessionSecret": "98ki^e72~!@#(85o3kXLI*#c9wu5l!Z", + "homepage": { + "enabled": false, + "title": "Welcome to MapJS", + "descriptionLine1": "The best place to find Pokemon, Raids, Quests, and more!", + "descriptionLine2": "Please login or join our Discord for more info...", + "discordInvite": "https://discord.gg/yourInvite" + }, + "map": { + "startLat": 0, + "startLon": 0, + "startZoom": 12, + "minZoom": 10, + "maxZoom": 18 + }, + "areas": { + "test": { + "lat": 4.01, + "lon": 117.01, + "zoom": 15 + } + }, + "header": { + "left": [ + { + "name": "Stats", + "url": "https://stats.example.com", + "icon": "fas fa-chart-bar" + } + ], + "right": [ + { + "name": "Discord", + "url": "https://discord.com", + "icon": "fab fa-discord" + } + ] + }, + "db": { + "scanner": { + "host": "127.0.0.1", + "port": 3306, + "username": "user", + "password": "pass123!", + "database": "rdmdb", + "charset": "utf8mb4", + "sessionTable": "sessions" }, - "header": { - "left": [ - { "name": "Stats", "url": "https://stats.example.com", "icon": "fas fa-chart-bar" } - ], - "right": [ - { "name": "Discord", "url": "https://discord.com", "icon": "fab fa-discord" } - ] + "manualdb": { + "host": "127.0.0.1", + "port": 3306, + "username": "user", + "password": "pass123!", + "database": "manualdb", + "charset": "utf8mb4" + } + }, + "discord": { + "enabled": false, + "logChannelId": "", + "status": "Map Status: Online", + "botToken": "", + "clientId": "", + "clientSecret": "", + "redirectUri": "http://localhost:8080/api/discord/callback", + "allowedGuilds": [], + "blockedGuilds": [], + "allowedUsers": [], + "perms": { + "map": { + "enabled": true, + "roles": [] + }, + "pokemon": { + "enabled": true, + "roles": [] + }, + "raids": { + "enabled": true, + "roles": [] + }, + "gyms": { + "enabled": true, + "roles": [] + }, + "pokestops": { + "enabled": true, + "roles": [] + }, + "quests": { + "enabled": true, + "roles": [] + }, + "lures": { + "enabled": true, + "roles": [] + }, + "invasions": { + "enabled": true, + "roles": [] + }, + "spawnpoints": { + "enabled": true, + "roles": [] + }, + "iv": { + "enabled": true, + "roles": [] + }, + "pvp": { + "enabled": true, + "roles": [] + }, + "s2cells": { + "enabled": true, + "roles": [] + }, + "submissionCells": { + "enabled": true, + "roles": [] + }, + "nests": { + "enabled": true, + "roles": [] + }, + "portals": { + "enabled": true, + "roles": [] + }, + "scanAreas": { + "enabled": true, + "roles": [] + }, + "weather": { + "enabled": true, + "roles": [] + }, + "devices": { + "enabled": true, + "roles": [] + } + } + }, + "tileservers": { + "Alidade Smooth Dark": "https://tiles.stadiamaps.com/tiles/alidade_smooth_dark/{z}/{x}/{y}{r}.png; © Stadia Maps, © OpenMapTiles © OpenStreetMap contributors", + "Thunder Forest": "https://{s}.tile.thunderforest.com/transport-dark/{z}/{x}/{y}.png;© Thunderforest, © OpenStreetMap contributors" + }, + "icons": { + "Default": { + "path": "https://mygod.github.io/pokicons/v2" }, - "db": { - "scanner": { - "host": "127.0.0.1", - "port": 3306, - "username": "user", - "password": "pass123!", - "database": "rdmdb", - "charset": "utf8mb4", - "sessionTable": "sessions" - }, - "manualdb": { - "host": "127.0.0.1", - "port": 3306, - "username": "user", - "password": "pass123!", - "database": "manualdb", - "charset": "utf8mb4" - } + "Local Example": { + "path": "/img/pokemon" }, - "discord": { - "enabled": false, - "logChannelId": "", - "status": "Map Status: Online", - "botToken": "", - "clientId": "", - "clientSecret": "", - "redirectUri": "http://localhost:8080/api/discord/callback", - "allowedGuilds": [], - "blockedGuilds": [], - "allowedUsers": [], - "perms": { - "map": { - "enabled": true, - "roles": [] - }, - "pokemon": { - "enabled": true, - "roles": [] - }, - "raids": { - "enabled": true, - "roles": [] - }, - "gyms": { - "enabled": true, - "roles": [] - }, - "pokestops": { - "enabled": true, - "roles": [] - }, - "quests": { - "enabled": true, - "roles": [] - }, - "lures": { - "enabled": true, - "roles": [] - }, - "invasions": { - "enabled": true, - "roles": [] - }, - "spawnpoints": { - "enabled": true, - "roles": [] - }, - "iv": { - "enabled": true, - "roles": [] - }, - "pvp": { - "enabled": true, - "roles": [] - }, - "s2cells": { - "enabled": true, - "roles": [] - }, - "submissionCells": { - "enabled": true, - "roles": [] - }, - "nests": { - "enabled": true, - "roles": [] - }, - "portals": { - "enabled": true, - "roles": [] - }, - "scanAreas": { - "enabled": true, - "roles": [] - }, - "weather": { - "enabled": true, - "roles": [] - }, - "devices": { - "enabled": true, - "roles": [] - } - } + "Home": { + "path": "https://raw.githubusercontent.com/Mygod/PkmnHomeIcons/icons/icons" }, - "tileservers": { - "Alidade Smooth Dark": "https://tiles.stadiamaps.com/tiles/alidade_smooth_dark/{z}/{x}/{y}{r}.png; © Stadia Maps, © OpenMapTiles © OpenStreetMap contributors", - "Thunder Forest": "https://{s}.tile.thunderforest.com/transport-dark/{z}/{x}/{y}.png;© Thunderforest, © OpenStreetMap contributors" - }, - "icons": { - "Default": { - "path": "https://mygod.github.io/pokicons/v2" - }, - "Local Example": { - "path": "/img/pokemon" - }, - "Home": { - "path": "https://raw.githubusercontent.com/Mygod/PkmnHomeIcons/icons/icons" - }, - "Shuffle": { - "path": "https://raw.githubusercontent.com/Mygod/pokedave_shuffle_icons_-ICONS-/master" - } + "Shuffle": { + "path": "https://raw.githubusercontent.com/Mygod/pokedave_shuffle_icons_-ICONS-/master" } -} + } +} \ No newline at end of file diff --git a/server/src/configs/default.json b/server/src/configs/default.json index 2245a7916..9d57006fb 100644 --- a/server/src/configs/default.json +++ b/server/src/configs/default.json @@ -273,5 +273,9 @@ "ultraRare": [], "regional": [], "event": [] + }, + "devOptions": { + "enabled": true, + "graphiql": true } } diff --git a/server/src/index.js b/server/src/index.js index ee5f8bc21..8efeb67b7 100644 --- a/server/src/index.js +++ b/server/src/index.js @@ -6,22 +6,12 @@ import '../knexfile.js' import rootRouter from './routes/rootRouter.js' import addMiddlewares from './middlewares/addMiddlewares.js' import hbsMiddleware from "express-handlebars" - -import { graphqlHTTP } from 'express-graphql' -import schema from './schema/schema.js' -import cors from 'cors' +import config from './services/config.js' const __filename = fileURLToPath(import.meta.url) const __dirname = dirname(__filename) const app = express() -const port = 3000 - -app.use(cors()) -app.use('/graphql', graphqlHTTP({ - schema, - graphiql: true -})) app.set("views", path.join(__dirname, "../views")) app.engine( @@ -43,8 +33,8 @@ addMiddlewares(app) app.use(rootRouter) -app.listen(port, () => { - console.log(`Server is now listening at http://localhost:${port}`) +app.listen(config.port, () => { + console.log(`Server is now listening at http://${config.interface}:${config.port}`) }) -export default app \ No newline at end of file +export default app diff --git a/server/src/routes/api/v1/dataRouter.js b/server/src/routes/api/v1/dataRouter.js deleted file mode 100644 index bddb0799c..000000000 --- a/server/src/routes/api/v1/dataRouter.js +++ /dev/null @@ -1,18 +0,0 @@ -import express from "express" -import config from '../../../services/config.js' - -const dataRouter = new express.Router() - -dataRouter.get("/settings", async (req, res) => { - try { - const settings = {} - settings.startLat = config.map.startLat - settings.startLon = config.map.startLon - settings.startZoom = config.map.startZoom - res.status(200).json({ settings }) - } catch (error) { - res.status(500).json({ error }) - } -}) - -export default dataRouter \ No newline at end of file diff --git a/server/src/routes/rootRouter.js b/server/src/routes/rootRouter.js index 15efc7945..1799355c3 100644 --- a/server/src/routes/rootRouter.js +++ b/server/src/routes/rootRouter.js @@ -1,11 +1,32 @@ import express from "express" import clientRouter from './clientRouter.js' -import dataRouter from './api/v1/dataRouter.js' +import { graphqlHTTP } from 'express-graphql' +import schema from '../schema/schema.js' +import config from '../services/config.js' +import cors from 'cors' const rootRouter = new express.Router() rootRouter.use("/", clientRouter) -rootRouter.use("/api/v1/data", dataRouter) +rootRouter.use('/graphql', cors(), graphqlHTTP({ + schema, + graphiql: config.devOptions.graphiql +})) + +rootRouter.get("/settings", async (req, res) => { + try { + const settings = {} + settings.env = config.devOptions.enabled + settings.map = config.map + settings.tileservers = config.tileservers + settings.icons = config.icons + settings.popUpDetails = config.popUpDetails + settings.rarity = config.rarity + res.status(200).json({ settings }) + } catch (error) { + res.status(500).json({ error }) + } +}) export default rootRouter