Skip to content

Commit

Permalink
Replace http-proxy server with BrowserSync proxy (docker developm…
Browse files Browse the repository at this point in the history
…ent) (#150)

* Remove `http-proxy` server

- make use of built in `browser-sync` proxy server within `gulpfile.js`
- remove `G3W_PROXY_ROUTES` within `config.template.js`

* update development URLs within `readme.md`

* Fix wrong merge

* Proxy routes fallback within `config.template.js` (v3.x)

* remove gulp task `plugins`

* remove "glob" need when updating plugin files

* refactor and simply vendors build chain

- remove `src/assets/vendors/index.css.html`
- remove `src/assets/vendors/index.js.html`
- remove `src/index.dev.html`
- rename `src/index.prod.html` into `src/index.html`
- deprecate config.js variables (`distFolder`, `clientFolder`, `admin_static_folder`, `admin_templates_folder`)
- add config.js variable: `admin_overrides_folder`
- add gulpfile.js internal variable (`outputFolder`) in order to properly handle `dev` and `build` tasks

* reduce delta

* update comments

* live reload application on plugin.js changes

* add comments and sort tasks

* handle `build:plugins` task in local development

* handle local developed plugins

- add parameter `devConfig` within `config.template.js`
- deprecate parameter `createProject` within `config.template.js`
- deprecate parameter `seCCurrentProject` within `config.template.js`
- automatically toggle `skin-blue` class on body tag (dev environment)
- refactor function `ApplicationService::obtainInitConfig()`
- move `require('app/dev')` into `src/app/main.js` (application entry point)

* micro-optimization (single glob watch)

* remove mandatory `gid` and `baseurl` options within `G3W_PLUGINS`

- convert variable `G3W_PLUGINS` into array (list of locally developed plugins)
- automatically assing `gid` and `baseurl` parameter for all locally developed plugins (ref: `src/app/dev/index.js`)

* generate `app.min.js.map` (PRODUCTION)

- add `gulp-sourcemaps` on production environment

* refactor browserify transform option

make use of `transform` option instead of chaining transform methods

* restore previous plugin developement tips (v3.4)

* restore vendors fonts in gulp chain

* Update "g3w-admin" and "g3w-suite-docker" badge versions

* set v3.5 also on badge image..

* Add some minimal info about "Plugins" development

* Align with dev new css and js vendors

* Comment change skin color to skin-blue on development environment to has the same color in production

* Rename admin_plugins_folder to admin_folder because it referred to g3w_admin folder and not to plugins

* Revert "Rename admin_plugins_folder to admin_folder because it referred to g3w_admin folder and not to plugins"

This reverts commit 186d37f

* Revert "Rename admin_plugins_folder to admin_folder because it referred to g3w_admin folder and not to plugins"

This reverts commit 186d37f

* replace "comment" section with a TODO

* Add deprecate wrapper comment to a part of code to extract project group, type and id parameters to get initial configuration from g3w-admin server

Co-authored-by: volterra79 <[email protected]>
  • Loading branch information
Raruto and volterra79 committed Jan 11, 2023
1 parent 74a69b9 commit 0230492
Show file tree
Hide file tree
Showing 13 changed files with 380 additions and 485 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ package-lock.json
/src/assets/style/less/g3w-skins-custom/
/src/libs/sdk/config/dev/
/src/libs/sdk/g3w-ol3/config/config.js
/src/index.html
/src/plugins/**
!/src/plugins/README.md
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ If everything went fine, you can now visit you local development server URL to s
# project_type = "qdjango";
# project_id = "1"

http://localhost:8000/en/map/countries/qdjango/1 # g3w-admin (production)
http://localhost:3000/?project=countries/qdjango/1 # g3w-client (development)
http://localhost:8000/en/map/countries/qdjango/1 # g3w-admin (production)
http://localhost:3000/en/map/countries/qdjango/1 # g3w-client (development)
```

```sh
Expand All @@ -118,10 +118,23 @@ http://localhost:3000/?project=countries/qdjango/1 # g3w-client (development)
# project_type = "qdjango";
# project_id = "2"

http://localhost:8000/en/map/eleprofile/qdjango/2 # g3w-admin (production)
http://localhost:3000/?project=eleprofile/qdjango/2 # g3w-client (development)
http://localhost:8000/en/map/eleprofile/qdjango/2 # g3w-admin (production)
http://localhost:3000/en/map/eleprofile/qdjango/2 # g3w-client (development)
```

### Plugins

If you want develop custom plugins you need to place them in the [`src/plugins`](https://github.com/g3w-suite/g3w-client/blob/dev/src/plugins) folder, below you can see some examples:

- [base-template](https://github.com/g3w-suite/g3w-client-plugin-base-template)
- [editing](https://github.com/g3w-suite/g3w-client-plugin-editing)
- [eleprofile](https://github.com/g3w-suite/g3w-client-plugin-elevation-profile)
- [openrouteservice](https://github.com/g3w-suite/g3w-client-plugin-openrouteservice)
- [qplotly](https://github.com/g3w-suite/g3w-client-plugin-qplotly)
- [qtimeseries](https://github.com/g3w-suite/g3w-client-plugin-qtimeseries)
- [queryresult-template](https://github.com/g3w-suite/g3w-client-plugin-queryresult-template)
- [sidebar-template](https://github.com/g3w-suite/g3w-client-plugin-sidebar-template)

---

### FAQ
Expand Down Expand Up @@ -217,8 +230,8 @@ All notable changes to this project are documented in the [releases](https://git
---

**Compatibile with:**
[![g3w-admin version](https://img.shields.io/badge/g3w--admin-3.4-1EB300.svg?style=flat)](https://github.com/g3w-suite/g3w-admin/tree/v.3.4.x)
[![g3w-suite-docker version](https://img.shields.io/badge/g3w--suite--docker-3.4-1EB300.svg?style=flat)](https://github.com/g3w-suite/g3w-suite-docker/tree/v3.4.x)
[![g3w-admin version](https://img.shields.io/badge/g3w--admin-3.5-1EB300.svg?style=flat)](https://github.com/g3w-suite/g3w-admin/tree/v.3.5.x)
[![g3w-suite-docker version](https://img.shields.io/badge/g3w--suite--docker-3.5-1EB300.svg?style=flat)](https://github.com/g3w-suite/g3w-suite-docker/tree/v3.5.x)

---

Expand Down
69 changes: 30 additions & 39 deletions config.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,59 @@ const G3W_HOST_SCHEMA = 'http';
const G3W_HOST = '127.0.0.1'; // local development server
const G3W_ADMIN_PORT = '8000'; // G3W-ADMIN development server
const G3W_CLIENT_PORT = '3000'; // G3W-CLIENT development server
const G3W_PROXY_ROUTES = [ // G3W-ADMIN routes to be proxied while developing
'/media',
'/api',
'/ows',
'/static',
'/en/',
'/it/',
'/upload/'
];

const G3W_PLUGINS = { // override "initConfig->group->plugins" attribute for custom plugin development
// "your-plugin-folder-name": {
// baseurl: '../dist',
// gid: 'qdjango:1' // 1 = current project id
// }
};
const G3W_PLUGINS = [ // override "initConfig->group->plugins" attribute for custom plugin development
// "your-plugin-folder-name-1",
// "your-plugin-folder-name-2",
// "your-plugin-folder-name-3",
];

const G3W_KEYS = {
// google: '<INSERT HERE YOUR GOOGLE API KEY>',
// bing: '<INSERT HERE YOUR BING API KEY>'
};

const G3W_ADMIN_PATH = '../g3w-admin/g3w-admin'; // path to G3W-ADMIN main code

let conf = {
assetsFolder: './src/assets', // path to G3W-CLIENT assets folder
pluginsFolder: './src/plugins', // path to G3W-CLIENT plugins folder
distFolder: './dist', // path to G3W-CLIENT dist folder
clientFolder: './dist/client', // path to G3W-CLIENT client folder
admin_plugins_folder: G3W_ADMIN_PATH, // path to G3W-ADMIN where are stored all plugin folders
admin_static_folder: `${G3W_ADMIN_PATH}/client/static`, // path to G3W-ADMIN client/static
admin_templates_folder: `${G3W_ADMIN_PATH}/client/templates`, // path to G3W-ADMIN client/templates
assetsFolder: './src/assets', // path to G3W-CLIENT assets folder
pluginsFolder: './src/plugins', // path to G3W-CLIENT plugins folder
admin_plugins_folder: '../g3w-admin/g3w-admin', // path to G3W-ADMIN plugins folder
admin_overrides_folder: '../g3w-suite-docker/config/g3w-suite/overrides', // path to G3W-SUITE overrides folder
host: G3W_HOST,
port: G3W_CLIENT_PORT,
// proxy configuration for local G3W_ADMIN server (where G3W-ADMIN is running)
proxy: {
host: G3W_HOST,
url: `${G3W_HOST_SCHEMA}://${G3W_HOST}:${G3W_ADMIN_PORT}/`,
routes: G3W_PROXY_ROUTES
},
test: {
path: '/test/config/groups/'
},
createProject: {
before(project) { /* code here */ },
after(project) { /* code here */ },
},
setCurrentProject: {
before(project) { /* code here */ },
after(project) { /* code here */ },
},
// override "initConfig->group->plugins" attribute for custom plugin development
plugins: G3W_PLUGINS,
keys: G3W_KEYS
keys: G3W_KEYS,
devConfig: function() {
g3wsdk.core.ApplicationService.once('ready', () => { });
g3wsdk.core.project.ProjectsRegistry.onbefore('createProject', (projectConfig) => {});
g3wsdk.core.project.ProjectsRegistry.onafter('createProject', (projectConfig) => {});
g3wsdk.core.project.ProjectsRegistry.onbefore('setCurrentProject', (project) => {});
g3wsdk.core.project.ProjectsRegistry.onafter('setCurrentProject', (project) => {});
g3wsdk.gui.GUI.once('ready', () => { console.log('ready'); });
}
};

// backward compatibilities (v3.x)
if (version < '4') {
conf.assetsFolder = (version < '3.7' ? './assets' : conf.assetsFolder);
conf.proxy.urls = conf.proxy.routes;
conf.localServerPort = conf.port;
conf.g3w_admin_paths = {
conf.assetsFolder = (version < '3.7' ? './assets' : conf.assetsFolder);
conf.distFolder = './dist';
conf.clientFolder = './dist/client';
conf.admin_static_folder = `${conf.admin_plugins_folder}/client/static`;
conf.admin_templates_folder = `${conf.admin_plugins_folder}/client/templates`;
conf.createProject = { before() {}, after() {} };
conf.setCurrentProject = { before() {}, after() {} };
conf.plugins = conf.plugins.reduce((a, v) => ({ ...a, [v]: { gid: 'qdjango:1', baseurl: `.${conf.distFolder}` }}), {});
conf.proxy.routes = ['/media', '/api', '/ows', '/static', '/en/', '/it/', '/upload/'];
conf.proxy.urls = conf.proxy.routes;
conf.localServerPort = conf.port;
conf.g3w_admin_paths = {
dev: {
g3w_admin_plugins_basepath: conf.admin_plugins_folder.replace(/\/?$/, '/'),
g3w_admin_client_dest_static: conf.admin_static_folder,
Expand Down
Loading

0 comments on commit 0230492

Please sign in to comment.