GitHub - fc-micro-frontends/career-up at step22
REACT_APP_AUTH0_DOMAIN=dev-vcrmf0xuep020tri.us.auth0.com
REACT_APP_AUTH0_CLIENT_ID=27LLb4I9cIjiiQNSjbNIX9sQM1KECUfk
REACT_APP_AUTH0_CALLBACK_URL=http://localhost:3000
REACT_APP_MICROAPP_POSTING=http://localhost:3001
REACT_APP_MICROAPP_EDU=http://localhost:3002
REACT_APP_MICROAPP_NETWORK=http://localhost:3003
REACT_APP_MICROAPP_JOB=http://localhost:3004
REACT_APP_FRAGMENT_RECOMMEND_CONNECTIONS=http://localhost:5001
REACT_APP_SERVER_URL=http://localhost:4000
➜ pnpm i
➜ pnpm build
➜ pnpm --filter @career-up/fragment-recommend-connections add swr
// career-up/fragments/fragment-recommend-connections/src/containers/recommend-connections-container.tsx
import React from "react";
import { useAuth0Client } from "@career-up/shell-router";
import RecommendConnections from "../components/recommend-connections";
import useSWR from "swr";
const SERVER_URL = process.env.REACT_APP_SERVER_URL!;
const RecommendConnectionsContainer: React.FC = () => {
const auth0Client = useAuth0Client();
const { data } = useSWR("/connections?_limit=3", async (url) => {
const token = await auth0Client.getTokenSilently();
const res = await fetch(`${SERVER_URL}${url}`, {
headers: {
Authorization: `Bearer ${token}`,
},
});
return await res.json();
});
return <RecommendConnections connections={data ?? []} />;
};
export default RecommendConnectionsContainer;
// career-up/fragments/fragment-recommend-connections/src/components/recommend-connections.tsx
import "./recommend-connections.css";
import React from "react";
import { type ConnectionType } from "../types";
import Connection from "./connection";
interface RecommendConnectionsProps {
connections: ConnectionType[];
}
const RecommendConnections: React.FC<RecommendConnectionsProps> = ({
connections,
}) => {
return (
<div className="fragment-recommend-connections--recommend-connections">
<div className="fragment-recommend-connections--recommend-connections-top">
<span className="fragment-recommend-connections--recommend-connections-top-title">
일촌 추천
</span>
</div>
<div className="fragment-recommend-connections--recommend-connections-bottom">
{connections.map((connection, index) => (
<Connection key={index} {...connection} />
))}
</div>
</div>
);
};
export default RecommendConnections;
// career-up/fragments/fragment-recommend-connections/webpack.config.js
const HtmlWebPackPlugin = require("html-webpack-plugin");
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
const Dotenv = require("dotenv-webpack");
const deps = require("./package.json").dependencies;
module.exports = (_, argv) => ({
output: {
publicPath: "<http://localhost:5001/>",
},
resolve: {
extensions: [".tsx", ".ts", ".jsx", ".js", ".json"],
},
devServer: {
port: 5001,
historyApiFallback: true,
},
module: {
rules: [
{
test: /\\.m?js/,
type: "javascript/auto",
resolve: {
fullySpecified: false,
},
},
{
test: /\\.(css|s[ac]ss)$/i,
use: ["style-loader", "css-loader", "postcss-loader"],
},
{
test: /\\.(ts|tsx|js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
},
},
],
},
plugins: [
new Dotenv({
path: "../../.env",
}),
new ModuleFederationPlugin({
name: "fragment_recommend_connections",
filename: "remoteEntry.js",
remotes: {},
exposes: {
"./container": "./src/containers/recommend-connections-container.tsx",
},
shared: {
...deps,
react: {
singleton: true,
requiredVersion: deps.react,
},
"react-dom": {
singleton: true,
requiredVersion: deps["react-dom"],
},
"@career-up/shell-router": {
singleton: true,
},
"@career-up/ui-kit": {
singleton: true,
},
**swr: {
version: deps["swr"],
},**
},
}),
new HtmlWebPackPlugin({
template: "./src/index.html",
}),
],
});
➜ pnpm --filter @career-up/fragment-recommend-connections build