본문 바로가기

Research/Server10

Koa_라우팅 const Koa = require('koa'); const Router = require('koa-router'); const app = new Koa(); const router = new Router(); router.get('/', (ctx) => { ctx.body = 'Home'; }); router.get('/about/:name?', (ctx) => { const { name } = ctx.params; ctx.body = name ? `${name}의 페이지` : 'About'; }); router.get('/posts', (ctx) => { const { id } = ctx.query; ctx.body = id ? `Post #${id}` : `There is no post..`; }).. 2023. 11. 1.
Koa_간단한 async/await 구현하기 // index.js const Koa = require('koa'); const app = new Koa(); app.use(async (ctx, next) => { console.log(ctx.url); console.log(1); if (ctx.query.authorized !== '1') { ctx.status = 401; // Unauthorized return; } // next().then(() => { // console.log('Done :D'); // }); await next(); console.log('Done :DD'); }); app.use((ctx, next) => { console.log(2); next(); }); app.use((ctx) => { ctx.body = 'he.. 2023. 10. 31.
Koa_파라미터 조건에 따른 미들웨어 실행하기 Koa에서 next()를 생략하면 다음 미들웨어는 실행하지 않는다. 이 원리를 이용해서 파라미터의 값에 따라 화면을 다르게 렌더링할 수 있다. // index.js const Koa = require('koa'); const app = new Koa(); app.use((ctx, next) => { console.log(ctx.url); console.log(1); if (ctx.query.authorized !== '1') { ctx.status = 401; // Unauthorized return; } next(); }); app.use((ctx, next) => { console.log(2); next(); }); app.use((ctx) => { ctx.body = 'hello world'; }).. 2023. 10. 31.
서버_AWS EC2 Ubuntu에 NGinx 설치하는 방법 들어가기 AWS EC2 Ubuntu에 Nginx를 설치하는 방법을 알아보자. (Ubuntu 버전은 18.04) 설치 # Nginx 설치 sudo apt-get install nginx # Nginx 폴더로 이동 cd /etc/nginx # Nginx 서버 실행 sudo service nginx start # Nginx 실행 확인 ps -ef | grep nginx접속 퍼블릭 IPv4 주소로 이동하면 Nginx가 반겨주는 화면이 뜬다. 만약 나오지 않는다면 80번 포트가 닫혀있을 가능성이 크니, EC2 인스턴스 보안그룹의 인바운드에 80포트를 열어주도록 하자. 환경설정 생성 Nginx config 구조 넘어가기 전에 nginx.conf 구조를 한번 체크하고 넘어가자면 이렇다. worker_processes.. 2023. 3. 6.