From ec805392cbb2e91b107e0203b250db6ba08644ba Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 2 Jul 2023 08:22:55 +0300 Subject: bridge: slimmed-down oembed server --- bridge/Dockerfile | 17 +++++++++++ bridge/ecosystem.config.js | 12 ++++++++ bridge/index.js | 25 +++++++++++++++++ bridge/webpack.config.js | 70 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 3 +- 5 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 bridge/Dockerfile create mode 100644 bridge/ecosystem.config.js create mode 100644 bridge/index.js create mode 100644 bridge/webpack.config.js diff --git a/bridge/Dockerfile b/bridge/Dockerfile new file mode 100644 index 00000000..5db05345 --- /dev/null +++ b/bridge/Dockerfile @@ -0,0 +1,17 @@ +FROM keymetrics/pm2:latest-alpine + +# Bundle APP files +COPY ../public/bridge.js . +COPY ecosystem.config.js . + +# Install app dependencies +ENV NPM_CONFIG_LOGLEVEL warn +ENV DEBUG http + +# Expose the listening port of your app +EXPOSE 8081 + +# Show current folder structure in logs +RUN ls -al -R + +CMD [ "pm2-runtime", "start", "ecosystem.config.js" ] diff --git a/bridge/ecosystem.config.js b/bridge/ecosystem.config.js new file mode 100644 index 00000000..40073998 --- /dev/null +++ b/bridge/ecosystem.config.js @@ -0,0 +1,12 @@ +module.exports = { + apps : [{ + name: 'bridge', + script: './bridge.js', + env: { + NODE_ENV: 'development', + }, + env_production: { + NODE_ENV: 'production', + } + }] + } diff --git a/bridge/index.js b/bridge/index.js new file mode 100644 index 00000000..8369f803 --- /dev/null +++ b/bridge/index.js @@ -0,0 +1,25 @@ +import express from 'express' +import { raw } from 'body-parser' +import cors from 'cors' +import debug from 'debug' +const log = debug('http') + +import oembed from '../vnext/server/middleware/oembed' + +const app = express() +app.use(raw()) +app.use(cors()) +const router = express.Router() + +router.get('/api/oembed', oembed) + +app.use(router) + +const PORT = 8081 +// start the app +app.listen(PORT, (error) => { + if (error) { + return console.log('something bad happened', error) + } + log('listening on ' + PORT + '...') +}) diff --git a/bridge/webpack.config.js b/bridge/webpack.config.js new file mode 100644 index 00000000..9467224d --- /dev/null +++ b/bridge/webpack.config.js @@ -0,0 +1,70 @@ +const ESLintPlugin = require('eslint-webpack-plugin') +const TerserPlugin = require('terser-webpack-plugin') + +module.exports = () => { + const node_env = process.env.NODE_ENV ? process.env.NODE_ENV : 'development' + const dev = node_env !== 'production' + const config = { + mode: node_env, + devtool: dev ? 'cheap-module-source-map' : false, + entry: { + 'bridge': [ + __dirname + '/index.js' + ] + }, + target: 'node', + output: { + path: __dirname + '/../public', + filename: '[name].js' + }, + module: { + rules: [{ + test: /\.js$/, + exclude: [ + /node_modules/ + ], + loader: 'babel-loader' + }, { + test: /\.(png|jpe?g|gif|svg)$/i, + type: 'asset/resource' + }] + }, + plugins: [ + ], + resolve: { + symlinks: false, + extensions: ['.js'] + } + } + if (dev) { + config.plugins.push( + new ESLintPlugin({ + files: __dirname + '/src', + lintDirtyModulesOnly: true, + failOnWarning: false, + failOnError: true, + fix: false + })) + config.devServer = { + hot: true, + historyApiFallback: true, + client: { + overlay: { + runtimeErrors: true + } + } + } + } + config.optimization = { + minimize: !dev, + minimizer: [ + new TerserPlugin({ + minify: TerserPlugin.swcMinify, + // `terserOptions` options will be passed to `swc` (`@swc/core`) + // Link to options - https://swc.rs/docs/config-js-minify + terserOptions: {}, + }), + ] + } + return config +} diff --git a/package.json b/package.json index 634bb2e7..f7519dea 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "vnext:build:ssr": "npm run vnext:build && webpack -c vnext/server/webpack.config.js --mode production", "vnext:start-ssr": "npm run vnext:build:ssr && cross-env DEBUG=http node --enable-source-maps public/server.js", "vnext:start": "cross-env NODE_ENV=development webpack serve -c vnext/webpack.config.js --mode development", - "vnext:lint": "eslint vnext" + "vnext:lint": "eslint vnext", + "bridge:build": "webpack -c bridge/webpack.config.js --mode production" }, "repository": { "type": "git", -- cgit v1.2.3