이어서 할 곳

GitHub - fc-micro-frontends/career-up at step7

server 워크스페이스 생성

packages:
  - "apps/*"
  - "packages/*"
  - "server"
➜ mkdir server

➜ cd server

➜ pnpm init

➜ cd ..
{
  **"name": "@career-up/server",**
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \\"Error: no test specified\\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}
➜ pnpm --filter @career-up/server add json-server@^0.17.4
// career-up/server/db.json
{
  "posts": [
    {
      "id": 1,
      "message": "지난 12월 15일, 쿠팡은 연말을 맞아 잠실 오피스에서 쿠팡 및 자회사 임직원을 위한 가족 행사 ‘엄마 아빠 회사는 처음이지?’를 진행하였습니다.",
      "createdAt": "2023-12-27T15:34:01.085Z",
      "author": {
        "email": "[email protected]",
        "name": "Mark Lee",
        "picture": "<https://lh3.googleusercontent.com/a/ACg8ocLQFU3l4dhf-6T83mF9ZcQ3NKDK3my_nOKuUhoIml3AkCU=s96-c>"
      }
    },
    {
      "id": 2,
      "message": "토스의 팀 빌딩을 함께할 (저희)팀원을 찾습니다! 💪<br /><br />Talent Engagement Partner(TEP) 팀은 Culture & Leadership Tribe 소속으로 토스 커뮤니티 내 C-Suite(CEO, CFO 등)을 포함한 Executive Position 을 채용하고 있어요.<br /><br />국내외 최고 수준의 인재들과 지속적인 관계를 형성하고, 이들을 채용하는 데 필요한 모든 프로세스를 담당하고 있어요.",
      "createdAt": "2023-12-27T15:34:01.085Z",
      "author": {
        "email": "[email protected]",
        "name": "Mark Lee",
        "picture": "<https://lh3.googleusercontent.com/a/ACg8ocLQFU3l4dhf-6T83mF9ZcQ3NKDK3my_nOKuUhoIml3AkCU=s96-c>"
      }
    },
    {
      "id": 3,
      "message": "지난주 '세바시HR강연회'의 마지막 회차를 맞이했습니다. 강렬하고 영감 넘치는 여정을 함께 해주셔서 감사드립니다.<br /><br />매 회차마다, 우리는 HR의 중요한 주제들을 다뤘습니다. HR환경에서 가져야 하는 경쟁력, 구성원들의 마음관리, 성장하는 조직문화 라는 주제들을 다뤘구요. 각 강연은 우리의 생각을 확장시키고 새로운 관점을 가지게 되는 계기가 되었습니다. 이러한 과정은 우리가 HR 분야에서 마주하는 도전과 기회를 더 잘 이해하고 대처하는 데 큰 도움이 되었습니다.<br /><br />이 멋진 여정의 일부가 될 수 있어서 좋았습니다. 모든 연사분들과 참여자 여러분께 진심으로 감사드립니다. 우리의 학습과 교류는 여기서 끝나지 않습니다. 앞으로도 서로 지원하고 성장하는 데 있어 계속해서 연결되기를 희망합니다.<br /><br />2024년도에 지속적으로 영감을 전할 수 있는 강연을 포함해 실전에 필요한 교육과 스터디를 운영 할 예정 입니다. 강사진으로 모시는 분들은 지속적으로 운영 될 웨비나를 통해서 세바시 무대에 설 수 있습니다.커뮤니티를 통해 배우시고 더 넓은 세상으로 함께 나아가길 바랍니다.<br /><br />강사진으로 참여하길 희망하시는 분들은 저에게 연락 주세요. HR특집 강연회를 놓치신 분들은 세바시 유튜브 채널을 통해서 확인해주세요. 12월 8일에 진행했던 강연은 댓글로 전달 드리는 링크를 통해서 최초 공개됩니다. 선공개 콘텐츠를 먼저 만나보고 싶으신 분들은 세바시랜드 모임에 가입해주세요.",
      "createdAt": "2023-12-27T15:34:01.085Z",
      "author": {
        "email": "[email protected]",
        "name": "Mark Lee",
        "picture": "<https://lh3.googleusercontent.com/a/ACg8ocLQFU3l4dhf-6T83mF9ZcQ3NKDK3my_nOKuUhoIml3AkCU=s96-c>"
      }
    },
    {
      "id": 4,
      "message": "- 올바른 프로젝트를 선택하는 것은 생산성의 가장 중요한 요소이다. 그러나 일반적으로 이것을 무시하는 경향이 있다.<br><br>- 생산성 메커니즘을 개선하기 전에 의미 있고 영향력 있는 프로젝트를 선택하는 것이 중요하다<br><br>- 마지막으로 다시 한 번 강조하지만, 잘못된 방향으로의 생산성은 전혀 가치가 없다. 어떤 작업을 할 것인지에 대해 더 많이 생각해야한다<br><br>- 생산성 자체는 노력의 방향을 안내하는 목적의식적이고 사려 깊은 목표 없이는 아무 의미가 없다",
      "createdAt": "2023-12-27T15:34:01.085Z",
      "author": {
        "name": "Mark Lee",
        "email": "[email protected]",
        "picture": "<https://lh3.googleusercontent.com/a/ACg8ocLQFU3l4dhf-6T83mF9ZcQ3NKDK3my_nOKuUhoIml3AkCU=s96-c>"
      }
    },
    {
      "id": 5,
      "message": "💗Presto Labs Year-end Party 2023💗<br>지난주 Presto Labs에서 year-end party 시간을 가졌습니다.<br>올 한해 동안 정말 많은 것들을 이뤄낸 우리 팀 동료들이 자랑스러웠네요.<br><br>함께 이루어낸 성취를 기뻐하고 기념하며, Work hard & play hard를 진심으로 보여주는 동료들 덕분에 행사 내내 웃음이 끊이질 않았습니다. <br>Presto 동료분들 올 한해 정말 수고 많으셨습니다! 덕분에 다가올 2024년도 많이 기대가 됩니다. :)<br><br>Last week, we wrapped up the year with an awesome party at Presto Labs.<br>I'm really proud of our team for all the amazing work we've done this year.<br><br>Celebrating our accomplishments together, and thanks to colleagues who truly showed the 'Work hard & play hard', the event was filled with laughter and fun moments.<br>Kudos to everyone at Presto for all the grit this year! Can't wait to see what 2024 has in store for us. Wishing everyone joyful end to the year. 🫶💌",
      "createdAt": "2023-12-27T15:34:52.328Z",
      "author": {
        "name": "Mark Lee",
        "email": "[email protected]",
        "picture": "<https://lh3.googleusercontent.com/a/ACg8ocLQFU3l4dhf-6T83mF9ZcQ3NKDK3my_nOKuUhoIml3AkCU=s96-c>"
      }
    }
  ]
}
// career-up/server/index.js

const jsonServer = require("json-server");
const server = jsonServer.create();
const router = jsonServer.router("db.json");
const middlewares = jsonServer.defaults();

const AUTH0_DOMAIN = "dev-vcrmf0xuep020tri.us.auth0.com";

server.use(middlewares);
server.use(async (req, res, next) => {
  if (await isAuthorized(req)) {
    next();
  } else {
    res.sendStatus(401);
  }
});
server.get("/user", (req, res) => {
  res.jsonp({ ...req.user, view_count: 249, update_count: 100 });
});

server.use(jsonServer.bodyParser);
server.post("/posts", (req, res, next) => {
  req.body.createdAt = new Date().toISOString();
  req.body.author = {
    name: req.user.name,
    email: req.user.email,
    picture: req.user.picture,
  };
  next();
});

server.use(router);
server.listen(4000, () => {
  console.log("JSON Server is running");
});

async function isAuthorized(req) {
  try {
    const Authorization = req.headers.authorization;

    const res = await fetch(`https://${AUTH0_DOMAIN}/userinfo`, {
      headers: {
        Authorization,
      },
    });

    const json = await res.json();

    req.user = json;

    return true;
  } catch (e) {
    return false;
  }
}
{
  "name": "@career-up/server",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    **"start:live": "node index"**
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "json-server": "^0.17.4"
  }
}
➜ pnpm --filter @career-up/server start:live

user 정보를 얻어오는 API 요청

➜ curl --location '<http://localhost:4000/user>' \\
--header 'Authorization: Bearer 토큰'

최종

GitHub - fc-micro-frontends/career-up at step8