From 635ba23e1cad8a4eb781a5cd2a89442575c58967 Mon Sep 17 00:00:00 2001 From: Ivan Beloborodov Date: Sun, 24 Dec 2023 08:11:31 +0300 Subject: [PATCH] Third-party data file access #1099 https dev server --- src/config/dev.js | 4 +++- webpack/server.js | 39 +++++++++++++++++++++++++++++++++++++-- webpack/webpack.dev.js | 3 ++- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/config/dev.js b/src/config/dev.js index 0d594590..86d24dac 100644 --- a/src/config/dev.js +++ b/src/config/dev.js @@ -1,11 +1,13 @@ import base from "./base"; +const pollingInterval = Number(__POLLING_INTERVAL__); + const dev = { apiUrl: "/api", dev: true, logMissingTranslations: true, logGraphQLErrors: true, - pollingInterval: 20000 + pollingInterval: pollingInterval ? pollingInterval * 1000 : 20000 }; export default { diff --git a/webpack/server.js b/webpack/server.js index 43c8ac03..5e330bca 100644 --- a/webpack/server.js +++ b/webpack/server.js @@ -30,7 +30,7 @@ const devServerConf = { } }; -// Setup API proxy +// Setup API and objects proxy if (process.env.PROD) { const { createProxyMiddleware } = require("http-proxy-middleware"); @@ -42,6 +42,14 @@ if (process.env.PROD) { changeOrigin: true }) ); + + app.use( + "/objects", + createProxyMiddleware({ + target: process.env.PROD, + changeOrigin: true + }) + ); } const devMiddleWare = require("webpack-dev-middleware")(compiler, devServerConf); @@ -62,4 +70,31 @@ app.get("*", (req, res) => { }); }); -app.listen(port); +if (process.env.HTTPS_CRT) +{ + const fs = require('fs'); + + const cert = fs.readFileSync(process.env.HTTPS_CRT, 'utf8'); + const key = fs.readFileSync(process.env.HTTPS_KEY, 'utf8'); + + const http = require('http'); + const https = require('https'); + + const url = require('url'); + + (http + .createServer((req, res) => { + const u = new url.URL('http://' + req.headers['host'] + req.url); + u.protocol = 'https:'; + u.port = port + 1; + res.writeHead(301, {"Location": u.toString()}); + res.end(); + }) + .listen(port)); + + (https + .createServer({key, cert}, app) + .listen(port + 1)); +} +else + app.listen(port); diff --git a/webpack/webpack.dev.js b/webpack/webpack.dev.js index c3a0a8a8..310592b7 100644 --- a/webpack/webpack.dev.js +++ b/webpack/webpack.dev.js @@ -61,7 +61,8 @@ base.plugins.push( new webpack.DefinePlugin({ "process.env.NODE_ENV": JSON.stringify("development"), __VERSION__: JSON.stringify(_.versionString), - __BUILD_YEAR__: JSON.stringify(_.buildYear) + __BUILD_YEAR__: JSON.stringify(_.buildYear), + __POLLING_INTERVAL__: JSON.stringify(process.env.POLLING_INTERVAL) }), new webpack.HotModuleReplacementPlugin(), new ReactRefreshWebpackPlugin(),