UNPKG

cloudux-starter-kit

Version:

Starter kit for UX developers in MediaCentral - NPM package

149 lines (148 loc) 5.04 kB
const fs = require('fs'); const path = require('path'); const { createProxyMiddleware } = require('http-proxy-middleware'); const proxy = createProxyMiddleware; const http2 = require('spdy'); const fetch = require('node-fetch'); const Config = require('../config').getData(); const https = require("https"); const { ContextExclusionPlugin } = require('webpack'); const agent = new https.Agent({ rejectUnauthorized: false }); Config.appName = require('../../../../../src/package.json').identity.appName; Config.main = require('../../../../../src/package.json').main; Config.avid = require('../../../../../src/package.json').avid; let host = ''; if (Config.hostPort && Config.hostPort.length > 0) { host = `${Config.hostIp}:${Config.hostPort}`; } else { host = Config.hostIp; } function injectApp(req, res, next) { try { fetch(`https://${host}${req.originalUrl}`, { method: 'GET', strictSSL: false, json: true, gzip: true, credentials: 'include', headers: req.headers, agent: agent }).then(response => { if (response.error) { console.error(response.error); next(); } return response.json(); }).then(data => { return data; }).then(data => { data.plugins.push({ folderName: Config.appName, main: Config.main, avid: Config.avid }); res.setHeader('Content-Type', 'application/json'); res.send(JSON.stringify(data)); return; }).catch(error => { console.trace(error); }); } catch (error) { console.error(error); } } ; const cert = fs.readFileSync(path.join(__dirname, '../../../../../certs/cert.crt')); const key = fs.readFileSync(path.join(__dirname, '../../../../../certs/cert.key')); const ca = fs.readFileSync(path.join(__dirname, '../../../../../certs/ca.crt')); module.exports = { // webpack-dev-server options publicPath: '/build/', hot: true, // Enable special support for Hot Module Replacement // Page is no longer updated, but a "webpackHotUpdate" message is sent to the content // Use "webpack/hot/dev-server" as additional module in your entry point // Note: this does _not_ add the `HotModuleReplacementPlugin` like the CLI option does. historyApiFallback: false, // Set this as true if you want to access dev server from arbitrary url. // This is handy if you are using a html5 router. compress: true, // Set this if you want to enable gzip compression for assets proxy: { '/': { target: `https://${host}`, secure: false, autoRewrite: true, ws: true, xfwd: false, changeOrigin: true, // needed for virtual hosted sites onProxyReq(proxyReq, req, res) { // Assets-4663: Publish updated version of cloudux-starter-kit (2024.10 compatible):: added req.url.startsWith('/pamctc/') as an additional filter: MN if (req.url.startsWith('/auth/') || req.url.startsWith('/api/') || req.url.startsWith('/apis/') || req.url.startsWith('/search/') || req.url.startsWith('/pamctc/')) { proxyReq.setHeader('x-forwarded-host', req.headers.host); } }, onProxyReqWs(proxyReq, req, socket, options, head) { proxyReq.setHeader('host', req.headers.host); } } }, // Set this if you want webpack-dev-server to delegate a single path to an arbitrary server. // Use "**" to proxy all paths to the specified server. // This is useful if you want to get rid of 'http://localhost:443/' in script[src], // and has many other use cases (see https://github.com/webpack/webpack-dev-server/pull/127 ). before: function (app) { // Here you can access the Express app object and add your own custom middleware to it. // For example, to define custom handlers for some paths: // serve local module from file system app.use(`/plugins/${Config.appName}`, (req, res, next) => { const url = req.originalUrl.replace(`/plugins/${Config.appName}`, ''); res.redirect(`/build/${url}`); }); // add local module to the list of plugins app.get(/\/apis\/avid\.plugins\.list;version=\d;realm=.+\/plugins/, (req, res, next) => { injectApp(req, res); }); app.get('/api/xlb/nodes/less', (req, res, next) => { res.json({ status: 'ok', data: { xlb_service_port: '5000', xlb_node_full_name: req.headers.host, xlb_node_active: '1' } }); }); const playbackProxy = proxy({ target: `https://${host}:5000`, secure: false }); const server = http2.createServer({ key, cert, ca }); server.listen(5000); server.on('upgrade', playbackProxy.upgrade); }, clientLogLevel: 'info', // Control the console log messages shown in the browser when using inline mode. Can be `error`, `warning`, `info` or `none`. // webpack-dev-middleware options quiet: false, noInfo: false, watchOptions: { aggregateTimeout: 300, poll: 1000 }, https: { cert, key, ca } };