* support for replay via replayweb.page embed, fixes #124 backend: - pre-sign all files urls - cache pre-signed urls in redis, presign again when expired (default duration 3600, settable via PRESIGN_DURATION_SECONDS env var) - change files output -> resources to confirm to Data Package spec supported by replayweb.page - add CrawlFileOut which contains 'name' (file id), 'path' (presigned url), 'hash', and 'size' - add /replay/sw.js endpoint to import sw.js from latest replay-web-page release - update to fastapi-users 9.2.2 - customize backend auth to allow authentication to check 'auth_bearer' query arg if 'Authorization' header not set - remove sw.js endpoint, handling in frontend frontend: - add <replay-web-page> to frontend, include rwp ui.js from latest release in index.html for now - update crawl api endpoint to end in json - replay-web-page loads the api endpoint directly! - update Crawl type to use new format, 'resources' -> instead of 'files', each file has 'name' and 'path' - nginx: add endpoint to serve the replay sw.js endpoint - add defer attr to ui.js - move 'Download' to 'Download Files' * frontend: support customizing replayweb.page loading url via RWP_BASE_URL env var in Dockerfile - default prod value set in frontend Dockerfile (set to upcoming 1.5.8 release needed for multi-wacz-file support) (can be overridden during image build via --build-arg) - rename index.html -> index.ejs to allow interpolation - RWP_BASE_URL defaults to latest https://replayweb.page/ for testing - for local testing, add sw.js loading via devServer, also using RWP_BASE_URL (#131) Co-authored-by: sua yoo <sua@suayoo.com>
137 lines
3.2 KiB
JavaScript
137 lines
3.2 KiB
JavaScript
// webpack.config.js
|
|
const path = require("path");
|
|
const ESLintPlugin = require("eslint-webpack-plugin");
|
|
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
|
const CopyPlugin = require("copy-webpack-plugin");
|
|
const Dotenv = require("dotenv-webpack");
|
|
|
|
const isDevServer = process.env.WEBPACK_SERVE;
|
|
|
|
// for testing: for prod, the Dockerfile should have the official prod version used
|
|
const RWP_BASE_URL = process.env.RWP_BASE_URL || "https://replayweb.page/";
|
|
|
|
const dotEnvPath = path.resolve(
|
|
process.cwd(),
|
|
`.env${isDevServer ? `.local` : ""}`
|
|
);
|
|
|
|
require("dotenv").config({
|
|
path: dotEnvPath,
|
|
});
|
|
|
|
const backendUrl = new URL(
|
|
process.env.API_BASE_URL || "https://btrix.webrecorder.net/"
|
|
);
|
|
const shoelaceAssetsSrcPath = path.resolve(
|
|
__dirname,
|
|
"node_modules/@shoelace-style/shoelace/dist/assets"
|
|
);
|
|
const shoelaceAssetsPublicPath = "shoelace/assets";
|
|
|
|
module.exports = {
|
|
entry: "./src/index.ts",
|
|
output: {
|
|
path: path.resolve(__dirname, "dist"),
|
|
filename: `js/[name]${isDevServer ? "" : ".[contenthash]"}.js`,
|
|
publicPath: "/",
|
|
},
|
|
|
|
devtool: "inline-source-map",
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.ts$/,
|
|
include: path.resolve(__dirname, "src"),
|
|
use: "ts-loader",
|
|
exclude: /node_modules/,
|
|
},
|
|
{
|
|
test: /\.css$/,
|
|
use: [
|
|
"style-loader",
|
|
{ loader: "css-loader", options: { importLoaders: 1 } },
|
|
"postcss-loader",
|
|
],
|
|
},
|
|
{
|
|
test: /\.html$/,
|
|
loader: "html-loader",
|
|
},
|
|
],
|
|
},
|
|
|
|
resolve: {
|
|
extensions: [".ts", ".js"],
|
|
},
|
|
|
|
devServer: {
|
|
watchFiles: ["src/*.js"],
|
|
open: true,
|
|
compress: true,
|
|
hot: true,
|
|
static: [
|
|
{
|
|
directory: shoelaceAssetsSrcPath,
|
|
publicPath: "/" + shoelaceAssetsPublicPath,
|
|
},
|
|
{
|
|
directory: path.join(__dirname),
|
|
//publicPath: "/",
|
|
watch: true,
|
|
},
|
|
],
|
|
historyApiFallback: true,
|
|
proxy: {
|
|
"/api": {
|
|
target: backendUrl.href,
|
|
headers: {
|
|
Host: backendUrl.host,
|
|
},
|
|
pathRewrite: { "^/api": "" },
|
|
},
|
|
},
|
|
// Serve replay service worker file
|
|
onBeforeSetupMiddleware: (server) => {
|
|
server.app.get("/replay/sw.js", (req, res) => {
|
|
res.set("Content-Type", "application/javascript");
|
|
res.send(`importScripts("${RWP_BASE_URL}sw.js")`);
|
|
});
|
|
},
|
|
port: 9870,
|
|
},
|
|
|
|
plugins: [
|
|
new Dotenv({ path: dotEnvPath }),
|
|
|
|
new HtmlWebpackPlugin({
|
|
template: "src/index.ejs",
|
|
templateParameters: {
|
|
rwp_base_url: RWP_BASE_URL,
|
|
},
|
|
// Need to block during local development for HMR:
|
|
inject: isDevServer ? "head" : true,
|
|
scriptLoading: isDevServer ? "blocking" : "defer",
|
|
}),
|
|
|
|
// Lint js files
|
|
new ESLintPlugin({
|
|
// lint only changed files:
|
|
lintDirtyModulesOnly: true,
|
|
// prevent warnings from stopping dev build
|
|
emitWarning: false,
|
|
// enable to auto-fix source files:
|
|
// fix: true
|
|
}),
|
|
|
|
new CopyPlugin({
|
|
patterns: [
|
|
// Copy Shoelace assets to dist/shoelace
|
|
{
|
|
from: shoelaceAssetsSrcPath,
|
|
to: path.resolve(__dirname, "dist", shoelaceAssetsPublicPath),
|
|
},
|
|
],
|
|
}),
|
|
],
|
|
};
|