Skip to content

Commit 15a878e

Browse files
authored
Merge pull request #833 from WatWowMap/better-multi-domain
feat: new approach to multi domain
2 parents 19803e7 + ba25048 commit 15a878e

21 files changed

+477
-98
lines changed

Diff for: .eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
dist
2+
dist-*
23
node_modules
34
public/missing-locales
45
public/images/custom

Diff for: .gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
node_modules
22
dist
3+
dist-*
34

45
# Config files
56
server/src/configs/*
@@ -10,6 +11,8 @@ server/src/configs/koji_backups/*
1011
!server/src/configs/areas.example.json
1112
!server/src/configs/local.example.json
1213
!server/src/configs/custom-environment-variables.json
14+
!server/src/configs/multi-domain-example/local.json
15+
!server/src/configs/multi-domain-example
1316
.env
1417

1518
# Masterfile

Diff for: .prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
dist
2+
dist-*
23
node_modules
34
public/missing-locales
45
public/images/custom

Diff for: CHANGELOG.md

+21-35
Original file line numberDiff line numberDiff line change
@@ -116,108 +116,94 @@
116116

117117
# [1.30.0-develop.6](https://github.com/WatWowMap/ReactMap/compare/v1.30.0-develop.5...v1.30.0-develop.6) (2024-02-23)
118118

119-
120119
### Bug Fixes
121120

122-
* refine ci ([515de64](https://github.com/WatWowMap/ReactMap/commit/515de64e6a7275b6b7afbdb287e18be15f373e4d))
121+
- refine ci ([515de64](https://github.com/WatWowMap/ReactMap/commit/515de64e6a7275b6b7afbdb287e18be15f373e4d))
123122

124123
# [1.30.0-develop.5](https://github.com/WatWowMap/ReactMap/compare/v1.30.0-develop.4...v1.30.0-develop.5) (2024-02-23)
125124

126-
127125
### Features
128126

129-
* pkmn filter diagram ([a40b201](https://github.com/WatWowMap/ReactMap/commit/a40b20123a78f3d565a47ed9266c16da3b979bdb))
127+
- pkmn filter diagram ([a40b201](https://github.com/WatWowMap/ReactMap/commit/a40b20123a78f3d565a47ed9266c16da3b979bdb))
130128

131129
# [1.30.0-develop.4](https://github.com/WatWowMap/ReactMap/compare/v1.30.0-develop.3...v1.30.0-develop.4) (2024-02-21)
132130

133-
134131
### Bug Fixes
135132

136-
* try/catch on expert filter just in case ([4e430e6](https://github.com/WatWowMap/ReactMap/commit/4e430e6e1e1729ef56095b7a414f9521c6d27d75))
133+
- try/catch on expert filter just in case ([4e430e6](https://github.com/WatWowMap/ReactMap/commit/4e430e6e1e1729ef56095b7a414f9521c6d27d75))
137134

138135
# [1.30.0-develop.3](https://github.com/WatWowMap/ReactMap/compare/v1.30.0-develop.2...v1.30.0-develop.3) (2024-02-21)
139136

140-
141137
### Bug Fixes
142138

143-
* normal form check ([47e358b](https://github.com/WatWowMap/ReactMap/commit/47e358b5cc01d75eb49cfa3b4654adf09b23af28))
139+
- normal form check ([47e358b](https://github.com/WatWowMap/ReactMap/commit/47e358b5cc01d75eb49cfa3b4654adf09b23af28))
144140

145141
# [1.30.0-develop.2](https://github.com/WatWowMap/ReactMap/compare/v1.30.0-develop.1...v1.30.0-develop.2) (2024-02-21)
146142

147-
148143
### Bug Fixes
149144

150-
* early version check ([c9d1295](https://github.com/WatWowMap/ReactMap/commit/c9d129597d00fbcc19b4f164f4ea1ca468f09fed))
145+
- early version check ([c9d1295](https://github.com/WatWowMap/ReactMap/commit/c9d129597d00fbcc19b4f164f4ea1ca468f09fed))
151146

152147
# [1.30.0-develop.1](https://github.com/WatWowMap/ReactMap/compare/v1.29.7-develop.5...v1.30.0-develop.1) (2024-02-21)
153148

154-
155149
### Features
156150

157-
* update polish locales ([#959](https://github.com/WatWowMap/ReactMap/issues/959)) ([d28dc0a](https://github.com/WatWowMap/ReactMap/commit/d28dc0af8445002f0f9b52e87f6eb08966182d24))
151+
- update polish locales ([#959](https://github.com/WatWowMap/ReactMap/issues/959)) ([d28dc0a](https://github.com/WatWowMap/ReactMap/commit/d28dc0af8445002f0f9b52e87f6eb08966182d24))
158152

159153
## [1.29.7-develop.5](https://github.com/WatWowMap/ReactMap/compare/v1.29.7-develop.4...v1.29.7-develop.5) (2024-02-12)
160154

161-
162155
### Bug Fixes
163156

164-
* more consistent gender filtering ([a3b24cb](https://github.com/WatWowMap/ReactMap/commit/a3b24cb6d4625c23d8d341c4b7cad62846b184c3))
157+
- more consistent gender filtering ([a3b24cb](https://github.com/WatWowMap/ReactMap/commit/a3b24cb6d4625c23d8d341c4b7cad62846b184c3))
165158

166159
## [1.29.7-develop.4](https://github.com/WatWowMap/ReactMap/compare/v1.29.7-develop.3...v1.29.7-develop.4) (2024-02-12)
167160

168-
169161
### Bug Fixes
170162

171-
* respect quest layer when searching ([4b0e0cc](https://github.com/WatWowMap/ReactMap/commit/4b0e0cc273b0e3c4988d4d3f0ded13053e3c75b6)), closes [#950](https://github.com/WatWowMap/ReactMap/issues/950)
163+
- respect quest layer when searching ([4b0e0cc](https://github.com/WatWowMap/ReactMap/commit/4b0e0cc273b0e3c4988d4d3f0ded13053e3c75b6)), closes [#950](https://github.com/WatWowMap/ReactMap/issues/950)
172164

173165
## [1.29.7-develop.3](https://github.com/WatWowMap/ReactMap/compare/v1.29.7-develop.2...v1.29.7-develop.3) (2024-02-12)
174166

175-
176167
### Bug Fixes
177168

178-
* `onlyShowAvailable` for nests selector ([068dac2](https://github.com/WatWowMap/ReactMap/commit/068dac25f7ffbb0594619202b85fa64801c835c8))
179-
* nest name memoization ([ec56d7d](https://github.com/WatWowMap/ReactMap/commit/ec56d7d79e0a5d53599307e2e3768b8dddce7852))
169+
- `onlyShowAvailable` for nests selector ([068dac2](https://github.com/WatWowMap/ReactMap/commit/068dac25f7ffbb0594619202b85fa64801c835c8))
170+
- nest name memoization ([ec56d7d](https://github.com/WatWowMap/ReactMap/commit/ec56d7d79e0a5d53599307e2e3768b8dddce7852))
180171

181172
## [1.29.7-develop.2](https://github.com/WatWowMap/ReactMap/compare/v1.29.7-develop.1...v1.29.7-develop.2) (2024-02-10)
182173

183-
184174
### Bug Fixes
185175

186-
* **nest:** make it compatible with previous tools ([9d97481](https://github.com/WatWowMap/ReactMap/commit/9d97481039356de2c1e6165abbb207a7d7af6cce))
187-
* **nest:** query only active nests ([ebb5295](https://github.com/WatWowMap/ReactMap/commit/ebb529578207e1d6a11f40a99e942030ec95c3e0))
176+
- **nest:** make it compatible with previous tools ([9d97481](https://github.com/WatWowMap/ReactMap/commit/9d97481039356de2c1e6165abbb207a7d7af6cce))
177+
- **nest:** query only active nests ([ebb5295](https://github.com/WatWowMap/ReactMap/commit/ebb529578207e1d6a11f40a99e942030ec95c3e0))
188178

189179
## [1.29.7-develop.1](https://github.com/WatWowMap/ReactMap/compare/v1.29.6...v1.29.7-develop.1) (2024-02-08)
190180

191-
192181
### Bug Fixes
193182

194-
* cache most things at process exit instead ([56eb47e](https://github.com/WatWowMap/ReactMap/commit/56eb47eca6e05f78e4b0b518b6d7fb6a5c901bc2))
195-
* config getters ([494639a](https://github.com/WatWowMap/ReactMap/commit/494639a28289fac90e0898cf2d443ba7a2c5c41d))
196-
* dont log golbat 404 pokemon id errors ([7292d13](https://github.com/WatWowMap/ReactMap/commit/7292d13f9b7460a7b40d1b3bcb45c751d183b953))
197-
* express session augmentation ([35533e9](https://github.com/WatWowMap/ReactMap/commit/35533e9b86518d496e71ff6a3fb93f54ad51864c))
198-
* favicon error catching for dummies ([b6c0fae](https://github.com/WatWowMap/ReactMap/commit/b6c0fae43ef8e4312bc61c265c8c16cd4a0c1ee5))
199-
* more client ts checks ([5028cb2](https://github.com/WatWowMap/ReactMap/commit/5028cb2221ac44e65620927bd69a10f4958f6d9c))
183+
- cache most things at process exit instead ([56eb47e](https://github.com/WatWowMap/ReactMap/commit/56eb47eca6e05f78e4b0b518b6d7fb6a5c901bc2))
184+
- config getters ([494639a](https://github.com/WatWowMap/ReactMap/commit/494639a28289fac90e0898cf2d443ba7a2c5c41d))
185+
- dont log golbat 404 pokemon id errors ([7292d13](https://github.com/WatWowMap/ReactMap/commit/7292d13f9b7460a7b40d1b3bcb45c751d183b953))
186+
- express session augmentation ([35533e9](https://github.com/WatWowMap/ReactMap/commit/35533e9b86518d496e71ff6a3fb93f54ad51864c))
187+
- favicon error catching for dummies ([b6c0fae](https://github.com/WatWowMap/ReactMap/commit/b6c0fae43ef8e4312bc61c265c8c16cd4a0c1ee5))
188+
- more client ts checks ([5028cb2](https://github.com/WatWowMap/ReactMap/commit/5028cb2221ac44e65620927bd69a10f4958f6d9c))
200189

201190
## [1.29.6](https://github.com/WatWowMap/ReactMap/compare/v1.29.5...v1.29.6) (2024-02-06)
202191

203-
204192
### Bug Fixes
205193

206-
* run even when prev is skipped ([78c1404](https://github.com/WatWowMap/ReactMap/commit/78c14040007a33180f5fddf270aa155136ba87c2))
194+
- run even when prev is skipped ([78c1404](https://github.com/WatWowMap/ReactMap/commit/78c14040007a33180f5fddf270aa155136ba87c2))
207195

208196
## [1.29.5](https://github.com/WatWowMap/ReactMap/compare/v1.29.4...v1.29.5) (2024-02-06)
209197

210-
211198
### Bug Fixes
212199

213-
* needs both ([e4b7cec](https://github.com/WatWowMap/ReactMap/commit/e4b7cec18ce2b41b04c5813b7a8ece23a3bf5510))
200+
- needs both ([e4b7cec](https://github.com/WatWowMap/ReactMap/commit/e4b7cec18ce2b41b04c5813b7a8ece23a3bf5510))
214201

215202
## [1.29.4](https://github.com/WatWowMap/ReactMap/compare/v1.29.3...v1.29.4) (2024-02-06)
216203

217-
218204
### Bug Fixes
219205

220-
* needs & attempt to not run double ([abcaaab](https://github.com/WatWowMap/ReactMap/commit/abcaaab5d65d68b98570727f21879e31f81f622e))
206+
- needs & attempt to not run double ([abcaaab](https://github.com/WatWowMap/ReactMap/commit/abcaaab5d65d68b98570727f21879e31f81f622e))
221207

222208
## [1.29.3](https://github.com/WatWowMap/ReactMap/compare/v1.29.2...v1.29.3) (2024-02-06)
223209

Diff for: jsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
"@store/*": ["./src/store/*"]
2020
}
2121
},
22-
"exclude": ["node_modules", "**/node_modules/*", "dist"]
22+
"exclude": ["node_modules", "**/node_modules/*", "dist", "dist-*"]
2323
}

Diff for: packages/config/lib/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ if (!process.env.NODE_CONFIG_DIR) {
1212
process.env.ALLOW_CONFIG_MUTATIONS = 'true'
1313
}
1414

15+
if (process.env.NODE_CONFIG_ENV) {
16+
if (
17+
process.env.NODE_CONFIG_ENV.includes('.') ||
18+
process.env.NODE_CONFIG_ENV.includes('/')
19+
) {
20+
throw new Error('Invalid NODE_CONFIG_ENV, must not contain "." or "/"')
21+
}
22+
}
23+
1524
const config = require('config')
1625

1726
config.getSafe = config.get

Diff for: packages/vite-plugins/lib/favicon.js

+25-25
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,36 @@ const { log, HELPERS } = require('@rm/logger')
99
* @returns {import('vite').Plugin}
1010
*/
1111
const faviconPlugin = (isDevelopment) => {
12-
try {
13-
const favicon = fs.existsSync(
14-
resolve(__dirname, '../../../public/favicon/favicon.ico'),
15-
)
16-
? resolve(__dirname, '../../../public/favicon/favicon.ico')
17-
: resolve(__dirname, '../../../public/favicon/fallback.ico')
18-
return {
19-
name: 'vite-plugin-favicon',
20-
generateBundle() {
21-
if (isDevelopment) return
12+
const basePath = resolve(__dirname, '../../../public/favicon')
13+
const fallback = resolve(basePath, `fallback.ico`)
14+
const custom = process.env.NODE_CONFIG_ENV
15+
? resolve(basePath, `${process.env.NODE_CONFIG_ENV}.ico`)
16+
: resolve(basePath, `favicon.ico`)
17+
const favicon = fs.existsSync(custom) ? custom : fallback
18+
return {
19+
name: 'vite-plugin-favicon',
20+
generateBundle() {
21+
if (isDevelopment) return
22+
try {
2223
this.emitFile({
2324
type: 'asset',
2425
fileName: 'favicon.ico',
2526
source: fs.readFileSync(favicon),
2627
})
27-
},
28-
configureServer(server) {
29-
server.middlewares.use((req, res, next) => {
30-
if (req.url === '/favicon.ico') {
31-
res.writeHead(200, { 'Content-Type': 'image/x-icon' })
32-
res.end(fs.readFileSync(favicon))
33-
return
34-
}
35-
next()
36-
})
37-
},
38-
}
39-
} catch (e) {
40-
log.error(HELPERS.build, 'Error loading favicon', e)
41-
return { name: 'vite-plugin-favicon' }
28+
} catch (e) {
29+
log.error(HELPERS.build, 'Error loading favicon', e)
30+
}
31+
},
32+
configureServer(server) {
33+
server.middlewares.use((req, res, next) => {
34+
if (req.url === '/favicon.ico') {
35+
res.writeHead(200, { 'Content-Type': 'image/x-icon' })
36+
res.end(fs.readFileSync(favicon))
37+
return
38+
}
39+
next()
40+
})
41+
},
4242
}
4343
}
4444

Diff for: server/src/configs/default.json

-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"enabled": false,
88
"graphiql": false,
99
"queryDebug": false,
10-
"clientPath": "../../dist",
1110
"logLevel": "info",
1211
"skipMinified": false
1312
},
@@ -117,7 +116,6 @@
117116
"bearerToken": "KOJI_SECRET"
118117
}
119118
},
120-
"multiDomains": [],
121119
"map": {
122120
"general": {
123121
"title": "ReactMap",

Diff for: server/src/configs/multi-domain-example/README.md

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Multi Domain Setup
2+
3+
## Overview
4+
- This makes use of the `NODE_CONFIG_ENV` env variable to determine which `local.json` files to load
5+
- Loads `default.json` => `local.json` => `local-{NODE_CONFIG_ENV}`.json
6+
- You set all of your base defaults in `local.json` still, then set things that are unique to those domains, such `geoJsonFilename` or authentication strategies in each of the domain specifics jsons
7+
- The `NODE_CONFIG_ENV` var names should not contain `/` or `.`
8+
9+
## File System
10+
```js
11+
// please note that this all goes in the parent `config` folder, not this example folder
12+
local.json
13+
local-applemap.json
14+
local-orangemap.json
15+
```
16+
17+
## Explanation of Config Files
18+
- `local.json` is the base config file that all other configs will inherit from, it can also be its own map instance if do not set the `NODE_CONFIG_ENV` env variable
19+
- The other files will inherit everything you set in `local.json` and then override any values that are set in the domain specific file
20+
- Such as in `local-applemap.json`, we have set a new title, a separate Discord strategy, and a different geoJsonFilename
21+
- Only config setting you must set in each file is the port, since separate instances of the app will be generated
22+
- In `local-orangemap.json`, we also set a different start Latitude and Longitude and have disabled some various features that we do not want on that map. In `local.json`, we had set `alwaysEnabledPerms = ["map"]`, however, for orangemap we have overridden that by providing an empty array.
23+
- The databases specified in `local.json` will be used in all 3 maps, as will all of the permissions.
24+
25+
## New PM2 `ecosystem.config.js` Example
26+
```js
27+
module.exports = {
28+
apps: [
29+
{
30+
name: 'ReactMap',
31+
script: 'ReactMap.js',
32+
instances: 1,
33+
autorestart: true,
34+
exec_mode: 'fork',
35+
max_memory_restart: '2G',
36+
},
37+
{
38+
name: 'AppleMap',
39+
script: 'ReactMap.js',
40+
instances: 1,
41+
autorestart: true,
42+
exec_mode: 'fork',
43+
max_memory_restart: '2G',
44+
env: {
45+
NODE_CONFIG_ENV: 'applemap',
46+
},
47+
},
48+
{
49+
name: 'OrangeMap',
50+
script: 'ReactMap.js',
51+
instances: 1,
52+
autorestart: true,
53+
exec_mode: 'fork',
54+
max_memory_restart: '2G',
55+
env: {
56+
NODE_CONFIG_ENV: 'orangemap',
57+
},
58+
},
59+
],
60+
}
61+
```
62+
63+
```sh
64+
# Start the app with the following command
65+
pm2 start ecosystem.config.js
66+
```
67+
68+
## Other Notes
69+
70+
- Be sure to view the `nginx` file to see how to set up the reverse proxy for the different domains
71+
- The domains do not have to be subdomains of each other, they can be whatever you want, they are just used to differentitate the different configs
72+
- The `NODE_CONFIG_ENV` var names should not contain `/` or `.`
73+
- The `NODE_CONFIG_ENV` value does not have to be related to the domain its representing. The URL for the map could be `https://www.my-super-map.com` and the `NODE_CONFIG_ENV` could be `applemap` or `orangemap` or `bananamap` or whatever you want, as long as you point the nginx reverse proxy to the correct instance of the app
74+
- Custom favicons can be set by putting the respective `{NODE_CONFIG_ENV}.ico` in the `public/favicon` folder
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"port": 8081,
3+
"map": {
4+
"general": {
5+
"title": "Apple Map",
6+
"headerTitle": "Apple Map PoGo",
7+
"geoJsonFilName": "http://koji.map.com/api/v1/geofence/feature-collection/apple"
8+
},
9+
"links": {
10+
"discordInvite": "apple map invite",
11+
"rolesLink": "apple map roles link"
12+
}
13+
},
14+
"authentication": {
15+
"strategies": [
16+
{
17+
"name": "this is your discord strategy for apple map",
18+
"enabled": false,
19+
"type": "discord",
20+
"logChannelId": "",
21+
"presence": "Map Status: Online",
22+
"presenceType": 3,
23+
"botToken": "",
24+
"clientId": "",
25+
"clientSecret": "",
26+
"redirectUri": "http://localhost:8081/auth/discord/callback",
27+
"allowedGuilds": [],
28+
"blockedGuilds": [],
29+
"allowedUsers": []
30+
}
31+
]
32+
}
33+
}

0 commit comments

Comments
 (0)