Static images through webpack copy (#3986)
* Static images through webpack copy * Turn image optimisation off - not needed tbh
This commit is contained in:
1 parent
19fe931f4b
commit
19e9e0083e
5 files changed
+101
-47
No files matched your search
@@ -64,3 +64,6 @@ tsconfig.tsbuildinfo
|
||||
|
||||
# Autogenerated embed content
|
||||
public/embed
|
||||
|
||||
# Copied app-store images
|
||||
public/app-store
|
||||
@@ -1,4 +1,5 @@
|
||||
require("dotenv").config({ path: "../../.env" });
|
||||
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
||||
|
||||
const withTM = require("next-transpile-modules")([
|
||||
"@calcom/app-store",
|
||||
@@ -77,7 +78,26 @@ plugins.push(withAxiom);
|
||||
/** @type {import("next").NextConfig} */
|
||||
const nextConfig = {
|
||||
i18n,
|
||||
experimental: {
|
||||
images: {
|
||||
unoptimized: true,
|
||||
},
|
||||
},
|
||||
webpack: (config) => {
|
||||
config.plugins.push(
|
||||
new CopyWebpackPlugin({
|
||||
patterns: [
|
||||
{
|
||||
from: "../../packages/app-store/*/static/**",
|
||||
to({ context, absoluteFilename }) {
|
||||
const appName = /app-store\/(.*)\/static/.exec(absoluteFilename);
|
||||
return Promise.resolve(`${context}/public/app-store/${appName[1]}/[name][ext]`);
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
);
|
||||
|
||||
config.resolve.fallback = {
|
||||
...config.resolve.fallback, // if you miss it, all the other options in fallback, specified
|
||||
// by next.js will be dropped. Doesn't make much sense, but how it is
|
||||
@@ -121,6 +141,11 @@ const nextConfig = {
|
||||
},
|
||||
async redirects() {
|
||||
const redirects = [
|
||||
{
|
||||
source: "/api/app-store/:path*",
|
||||
destination: "/app-store/:path*",
|
||||
permanent: true,
|
||||
},
|
||||
{
|
||||
source: "/settings",
|
||||
destination: "/settings/profile",
|
||||
|
||||
@@ -151,6 +151,7 @@
|
||||
"@types/uuid": "8.3.1",
|
||||
"autoprefixer": "^10.4.7",
|
||||
"babel-jest": "^28.1.0",
|
||||
"copy-webpack-plugin": "^11.0.0",
|
||||
"env-cmd": "^10.1.0",
|
||||
"eslint": "^8.20.0",
|
||||
"jest": "^28.1.0",
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
import fs from "fs";
|
||||
import mime from "mime-types";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import path from "path";
|
||||
|
||||
/**
|
||||
* This endpoint should allow us to access to the private files in the static
|
||||
* folder of each individual app in the App Store.
|
||||
* @example
|
||||
* ```text
|
||||
* Requesting: `/api/app-store/zoomvideo/icon.svg` from a public URL should
|
||||
* serve us the file located at: `/packages/app-store/zoomvideo/static/icon.svg`
|
||||
* ```
|
||||
* This will allow us to keep all app-specific static assets in the same directory.
|
||||
*/
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const queryParts = Array.isArray(req.query.static) ? req.query.static : [req.query.static];
|
||||
let appPath, fileName;
|
||||
if (queryParts[0] === "ee") {
|
||||
const appName = queryParts[1];
|
||||
if (!appName) {
|
||||
return res.status(400).json({ error: true, message: "No app name provided" });
|
||||
}
|
||||
appPath = path.join("ee", appName);
|
||||
fileName = queryParts[2];
|
||||
} else {
|
||||
[appPath, fileName] = queryParts;
|
||||
}
|
||||
|
||||
if (!fileName) {
|
||||
return res.status(400).json({ error: true, message: "No file name provided" });
|
||||
}
|
||||
if (!appPath) {
|
||||
return res.status(400).json({ error: true, message: "No app name provided" });
|
||||
}
|
||||
const fileNameParts = fileName.split(".");
|
||||
const { [fileNameParts.length - 1]: fileExtension } = fileNameParts;
|
||||
const STATIC_PATH = path.join(process.cwd(), "..", "..", "packages/app-store", appPath, "static", fileName);
|
||||
try {
|
||||
const imageBuffer = fs.readFileSync(STATIC_PATH);
|
||||
const mimeType = mime.lookup(fileExtension);
|
||||
if (mimeType) res.setHeader("Content-Type", mimeType);
|
||||
res.send(imageBuffer);
|
||||
} catch (e) {
|
||||
res.status(400).json({ error: true, message: "Resource not found" });
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user