feature: handle multiple configs

This commit is contained in:
Jean-Baptiste Pasquier 2020-12-14 11:24:35 +01:00
parent 7b87f436a0
commit deb3b25520
No known key found for this signature in database
GPG Key ID: CC04B91B949C163A
7 changed files with 169 additions and 116 deletions

21
.gitignore vendored
View File

@ -1,13 +1,22 @@
**/node_modules
config.json
.DS_Store
*.iml
*.swp
dist
.npm
# Test cache
cache
cypress/screenshots
cypress/videos
cache
.npm
.DS_Store
src/manifest.webmanifest
# Built files
.cache
dist
# Config specific files
config.json
config.*.json
!config.sample.json
# PWA Generated file
src/manifest.webmanifest

View File

@ -71,6 +71,22 @@ Serve, watch files & rebuild on change with this command:
npm run watch
```
### Multiple config.json
You can have as many `config.*.json` as you need.
Watch on a custom config file:
```bash
CONFIG_PATH='config.customName.json' npm run watch
```
Build with a custom config file:
```bash
CONFIG_PATH='config.customName.json' npm run build
```
## Mandatory modules
By default, a Hubl includes only individual chat modules.
@ -86,10 +102,15 @@ On `config.json`:
"clientLogo": "/images/logo.webp",
"authority": "http://localhost:8000/",
"endpoints": {
"get": {
"skills": "http://server.url/skills/",
"users": "http://server.url/users/"
},
"post": {
"users": "http://server.url/users/",
"uploads": "http://server.url/upload/"
}
}
}
```
@ -99,9 +120,9 @@ Where:
* `clientLogo` is an URL to an image file
* `xmppWebsocket` is your [Prosody](https://prosody.im/) with [appropriate modules](https://git.startinblox.com/infra/prosody-modules/) configured on.
* `authority` is the OpenID Provider. Usually, if you use `djangoldp-account` it's the same as your djangoldp server.
* `endpoints.users` is the API endpoints for Users on your djangoldp server. (djangoldp-account)
* `endpoints.skills` is the API endpoints for Skills on your djangoldp server. (djangoldp-skill)
* `endpoints.uploads` is the API endpoints for Uploads on your djangoldp server. (djangoldp-upload)
* `endpoints.*.users` is the API endpoints for Users on your djangoldp server. (djangoldp-account)
* `endpoints.*.skills` is the API endpoints for Skills on your djangoldp server. (djangoldp-skill)
* `endpoints.*.uploads` is the API endpoints for Uploads on your djangoldp server. (djangoldp-upload)
### Communities
@ -157,7 +178,12 @@ On `config.json`:
```json
"endpoints": {
"get": {
"circle": "http://server.url/circles/"
},
"post": {
"circle": "http://server.url/circles/"
},
}
```
@ -171,8 +197,10 @@ On `config.json`:
```json
"endpoints": {
"get": {
"dashboard": "http://server.url/dashboard/"
}
}
```
A [sample fixture](https://git.startinblox.com/djangoldp-packages/djangoldp-dashboard/blob/master/djangoldp_dashboard/fixtures/sample.json) can be loaded with `./manage.py loaddata sample`.
@ -187,9 +215,9 @@ On `config.json`:
```json
"endpoints": {
"joboffers": "http://server.url/job-offers/",
"skills": "http://server.url/skills/",
"uploads": "http://server.url/upload/"
"get": {
"joboffers": "http://server.url/job-offers/"
}
}
```
@ -203,10 +231,12 @@ On `config.json`:
```json
"endpoints": {
"projects": "http://server.url/projects/",
"customers": "http://server.url/customers/",
"businessproviders": "http://server.url/businessproviders/",
"skills": "http://server.url/skills/"
"get": {
"projects": "http://server.url/projects/"
},
"post": {
"projects": "http://server.url/projects/"
}
}
```
@ -219,12 +249,7 @@ On Server: `djangoldp_skill`, `djangoldp_upload` packages
On `config.json`:
```json
"publicDirectory": true,
"endpoints": {
"groups": "http://server.url/groups/",
"skills": "http://server.url/skills/",
"uploads": "http://server.url/upload/"
}
"publicDirectory": true
```
## Optional community modules
@ -241,9 +266,14 @@ On `config.json`:
```json
"endpoints": {
"get": {
"events":"http://server.url/events/",
"typeevents":"http://server.url/typeevents/",
"uploads": "http://server.url/upload/"
"typeevents":"http://server.url/typeevents/"
},
"post": {
"events":"http://server.url/events/",
"typeevents":"http://server.url/typeevents/"
}
}
```
@ -259,10 +289,16 @@ On `config.json`:
```json
"endpoints": {
"get": {
"resources":"http://server.url/resources/",
"resourceskeywords":"http://server.url/keywords/",
"resourcestypes":"http://server.url/types/",
"uploads": "http://server.url/upload/"
"resourcestypes":"http://server.url/types/"
},
"post": {
"resources":"http://server.url/resources/",
"resourceskeywords":"http://server.url/keywords/",
"resourcestypes":"http://server.url/types/"
}
}
```
@ -276,7 +312,12 @@ On `config.json`:
```json
"endpoints": {
"get": {
"polls":"http://server.url/polls/"
},
"post": {
"polls":"http://server.url/polls/"
}
}
```

View File

@ -6,13 +6,11 @@
"endpoints": {
"get": {
"skills": "http://localhost:8000/skills/",
"users": "http://localhost:8000/users/",
"groups": "http://localhost:8000/groups/"
"users": "http://localhost:8000/users/"
},
"post": {
"skills": "http://localhost:8000/skills/",
"users": "http://localhost:8000/users/",
"groups": "http://localhost:8000/groups/"
"upload": "http://localhost:8000/upload/"
}
}
}

View File

@ -2,7 +2,7 @@ const HTMLAsset = require('parcel-bundler/lib/assets/HTMLAsset')
function shouldIgnore (file) {
// Ignore img(src="${...}") on pug & keep the components folder pristine
return /\${.+}/.test(file) || /components/.test(file);
return /\${.+}/.test(file) || /components/.test(file) || /\/lib\/solid-/.test(file);
}
class SkipStartinbloxWidgetAsset extends HTMLAsset {

View File

@ -26,12 +26,14 @@ const options = {
};
(async function() {
if(!fs.existsSync("config.json")) throw "[Error] (Mandatory) Missing config.json file";
let configPath = process.env.CONFIG_PATH || 'config.json';
if(!fs.existsSync(configPath)) throw `[Error] (Mandatory) Missing ${configPath} file`;
console.log(`Using ${configPath} config file`);
let config = JSON.parse(fs.readFileSync('config.json'));
let config = JSON.parse(fs.readFileSync(configPath));
if(!config.clientName) throw "[Error] (Mandatory) Missing clientName on config.json";
if(!config.clientLogo) throw "[Error] (Mandatory) Missing clientLogo on config.json";
if(!config.clientName) throw `[Error] (Mandatory) Missing clientName on ${configPath}`;
if(!config.clientLogo) throw `[Error] (Mandatory) Missing clientLogo on ${configPath}`;
let manifest = {
"lang": "fr",

View File

@ -1,4 +1,5 @@
const config = require("../config.json");
let configPath = process.env.CONFIG_PATH || 'config.json';
const config = require(`../${configPath}`);
module.exports = {
locals: config

View File

@ -30,7 +30,8 @@ self.addEventListener('activate', function (e) {
self.clients.claim();
});
self.addEventListener('fetch', function (event) {
if(process.env.NODE_ENV === 'production'){
self.addEventListener('fetch', function (event) {
let requestURL = new URL(event.request.url);
if (requestURL.origin == location.origin) {
// Static asset, cache then network
@ -110,4 +111,5 @@ self.addEventListener('fetch', function (event) {
}
}
}
});
});
}