Skip to content

Commit

Permalink
Third-party data file access #1099 https dev server
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Beloborodov committed Dec 24, 2023
1 parent 429d9b2 commit 635ba23
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/config/dev.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
39 changes: 37 additions & 2 deletions webpack/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const devServerConf = {
}
};

// Setup API proxy
// Setup API and objects proxy
if (process.env.PROD) {
const { createProxyMiddleware } = require("http-proxy-middleware");

Expand All @@ -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);
Expand All @@ -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);
3 changes: 2 additions & 1 deletion webpack/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 635ba23

Please sign in to comment.