// n개의 요소를 가진 배열 생성하기
const arr = Array(n);

// 배열에 동일한 데이터 채우기
// 모든 요소를 5로 채울 경우
arr.fill(5);

 

 

 

https://nextjs.org/docs/advanced-features/middleware

 

Advanced Features: Middleware (Beta) | Next.js

Learn how to use Middleware in Next.js to run code before a request is completed.

nextjs.org

 

 

import { NextFetchEvent, NextRequest, NextResponse } from "next/server";
import jwtDecode from "jwt-decode";
import CustomJwtPayload from "@/util/jwt/CustomJwtPayload";

// 리프레시 토큰 관리를 위한 미들웨어 제작
export function middleware(req: NextRequest, ev: NextFetchEvent) {
  // 스태틱파일 구분을 위한 정규표현식
  const PUBLIC_FILE = /\.(.*)$/;

  const { origin, pathname } = req.nextUrl;

  // 스태틱파일이 아니거나 로그인 관련 주소가 아니면 조건실행
  if (!PUBLIC_FILE.test(pathname) && !pathname.includes("/sign")) {
    console.log(req.nextUrl);

    const refreshToken = req.cookies["refresh_token"];
    const nowTimestamp = new Date().getTime();

    // 만료일 초기화
    let exp = -1;

    // 디코딩하여 만료일 체크
    try {
      exp = jwtDecode<CustomJwtPayload>(refreshToken).exp * 1000;
    } catch (e) {
      // 토큰이 디코딩 되지 않으면 로그인 페이지로 이동
      return NextResponse.redirect(`${origin}/sign/in`);
    }

    // 만료되었으면 로그인 페이지로 이동
    if (exp < nowTimestamp) {
      return NextResponse.redirect(`${origin}/sign/in`);
    }
  }
}

 

 

 

 

let params = new URLSearchParams(location.search);
params.set("page", "0");
location.href = `/question?${params.toString()}`;

 

 

 

 

 

 

 

 

 

 

 

See the Pen Untitled by jaybon (@jaybon1) on CodePen.

'Web > Html_Css' 카테고리의 다른 글

HTML로 리다이렉트 하기  (0) 2021.09.29
부트스트랩 태그 중앙정렬  (0) 2020.06.26
css 사이즈 원하는대로 조절하려면  (0) 2020.06.22
부트스트랩 사이트 모음  (0) 2020.06.22
그리드 grid 사용법  (0) 2020.06.19

 

자바스크립트를 사용하지 못하는 환경이거나 HTML만 사용할 수 있는 환경에서 주소 이동을 하고 싶은 경우 사용한다.

ex) aws 로드밸런서의 리 다이렉션 등 (https -> http로 리다이렉트도 가능)

보안적인 이슈가 있을 수 있으니 조심하여 사용할 것

text/html 타입으로 설정한 뒤 head 태그 안에 meta 태그를 넣어준다.

content 안의 0은 리다이렉션 대기 시간이고 세미콜론 이후에 주소를 넣어준다.

<html>
  <head>
    <meta http-equiv="refresh" content="0;url=http://www.google.com/">
  </head>
</html>

'Web > Html_Css' 카테고리의 다른 글

style display 옵션 테스트  (0) 2021.11.20
부트스트랩 태그 중앙정렬  (0) 2020.06.26
css 사이즈 원하는대로 조절하려면  (0) 2020.06.22
부트스트랩 사이트 모음  (0) 2020.06.22
그리드 grid 사용법  (0) 2020.06.19

 

리액트에서

A component is changing a controlled input to be uncontrolled. This is likely caused by the value changing from a defined to undefined, which should not happen. Decide between using a controlled or uncontrolled input element for the lifetime of the component.

에러가 발생할 경우 값변경이 제대로 되지 않는 경우가 있다

이 경우는 받아온 DTO나 state가 null일 경우이다

 

value={dto.name}

이렇게 들어간 코드를

value={dto.name || ''}

이런식으로  널처리를 해주면 해결된다.

'Web > ReactJS' 카테고리의 다른 글

NextJS 미들웨어  (0) 2022.04.20
NextJS Api 키 등 중요 변수 숨기기  (0) 2022.04.19
intellij 인텔리제이 eslint typescript prettier  (0) 2021.02.19
react js / next js quill 적용  (0) 2021.02.17
next js 시작하기  (0) 2021.02.15

+ Recent posts