diff options
Diffstat (limited to 'bridge')
-rw-r--r-- | bridge/Dockerfile | 17 | ||||
-rw-r--r-- | bridge/ecosystem.config.js | 12 | ||||
-rw-r--r-- | bridge/index.js | 25 | ||||
-rw-r--r-- | bridge/webpack.config.js | 70 |
4 files changed, 124 insertions, 0 deletions
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 +} |