본문 바로가기

NextJs5

NextJS를 API로만 이용할때 CORS 에러 대처 방법 파일명은 middleware.ts으로 사용되야 하고 위치는 루트(/) 위치 즉 package.json 파일 위치와 같아야 한다. import { NextResponse } from "next/server"; // the list of all allowed origins const allowedOrigins = [ 'http://localhost:3011', ]; export function middleware(req: any) { // retrieve the current response const res = NextResponse.next() // retrieve the HTTP "Origin" header // from the incoming request let origin = req.headers.. 2023. 8. 8.
ㅇ NextJS server.js localhost https로 사용하기(개발 용) const { createServer } = require("https"); const { parse } = require("url"); const next = require("next"); const fs = require("fs"); const hostname = "localhost"; const port = 3000; const dev = process.env.NODE_ENV !== "production"; const app = next({ dev, hostname, port }); const handle = app.getRequestHandler(); const httpsOptions = { key: fs.readFileSync("localhost+1-key.pem"), cert: fs.readF.. 2023. 6. 1.
시놀로지 https SSL 서버 설정하기(NodeJS 서버도 가능) 뭐 Docker로 한다는 이야기도 있지만 내가 개발한 NextJS 앱은 작동이 안됨. 그래서 혹시나 해서 그냥 아무 폴더를 만들고 거기서 내 소스를 올리고 내 로컬 PC와 똑같이 npm run dev 하면 3000 포트가 열리게 되는데 그럼 내부망 http://192.168.0.X:3000 접속하고 잘 열리는것을 확인 후 시놀로지->제어판->응용 프로그램->응용 프로그램 포털->역방향 프록시 X.synology.me는 자신의 내용으로 수정 해주세요 그리고 https://X.synology.me 로 접속 하시면 https가 잘 적용된 사이트 화면이 나올꺼임 참고로 이렇게 설정하면 기존 Web Station 동작이 역방향 프록시로 교체 됨 2023. 4. 24.
NextJS를 vscode로 Debugging 하는 방법 .vscode/launch.json 생성 { "version": "0.2.0", "configurations": [ { "type": "node", "request": "attach", "name": "Next.js: debug full stack", "skipFiles": ["/**"], "port": 9229 } ] } package.json 수정 "scripts": { "dev": "cross-env NODE_OPTIONS='--inspect' next dev", ... }, 윈도우에서는 cross-env 설치 필요 npm i cross-env !!이제 환경 설정은 끝났음!! npm run dev 실행 후 vscode에서 Ctrl+Shift+D 클릭 해서 Run & Debug 로 이동 Next.js.. 2023. 4. 24.