★코드 분석

redux-react-typescript

용성 2021. 8. 31. 21:59

https://github.com/jaysoo/todomvc-redux-react-typescript

 

GitHub - jaysoo/todomvc-redux-react-typescript: TodoMVC example using Redux, React, and Typescript

TodoMVC example using Redux, React, and Typescript - GitHub - jaysoo/todomvc-redux-react-typescript: TodoMVC example using Redux, React, and Typescript

github.com

 

- client와 server로 나뉜다.

 

- production server 상품 서버가 존재한다.

 

→ server / setUp.js

const path = require('path');
const compression = require('compression');
const express = require('express');
const http = require('http');
const chalk = require('chalk');

const isProd = process.env.NODE_ENV === 'production';
const port = process.env.PORT || 3000;

module.exports = function (options) {
  const app = express();

  if (isProd) {
    addProdMiddlewares(app, options);
  } else {
    const webpackConfig = require('../internals/webpack/webpack.dev.config');
    addDevMiddlewares(app, webpackConfig);
  }

  // serve the static assets
  app.use("/_assets", express.static(path.join(__dirname, "..", "build", "public"), {
    maxAge: "200d" // We can cache them as they include hashes
  }));
  app.use("/", express.static(path.join(__dirname, "..", "public"), {
  }));

  app.get("/*", function(req, res) {
    renderer.render(
      req.path,
      function(err, html) {
        if(err) {
          res.statusCode = 500;
          res.contentType = "text; charset=utf8";
          res.end(err.message);
          return;
        }
        res.contentType = "text/html; charset=utf8";
        res.end(html);
      }
    );
  });

  const server = http.createServer(app);

 

 

아직 express로 서버를 구현한 적이 없었는데, 이 방법을 사용하여

api 호출을 해봐야겠다.

728x90