e_yejun
Jun_ : Pwn
e_yejun
전체 방문자
오늘
어제
  • 분류 전체보기 (240)
    • Profile (1)
    • Pwnable (54)
    • Reversing (14)
    • Network (8)
    • Forensic (10)
    • Embedded (4)
    • Android (2)
    • Web (18)
    • 알고리즘 (42)
    • 프로그래밍 (24)
    • 프로젝트 (6)
    • 1-day (7)
    • CTF (15)
    • 기타 (33)
    • 일기장 (0)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • x64
  • 1-day
  • wargame
  • how2heap
  • dvwa
  • BOF
  • X86
  • dreamhack.io
  • Heap
  • rev-basic

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
e_yejun

Jun_ : Pwn

프로그래밍

[Node.js] Express sendFile 에서 외부 JS 파일을 포함하기

2020. 10. 4. 13:19

 

NodeJS Express sendFile 에서 서버에 접속하는 클라이언트에게 html파일을 보내줄 경우,

그 html파일 안에 있는 js의 외부주소 파일을 기존과 다른 방식으로 포함시켜야 한다.

 

 

 

외부 js 파일 포함시키는 방법 (server)

app.use('/js', express.static(__dirname + '/js'));

 

 

외부 js 파일 포함시키는 방법 (client)

<script src='localhost:port/js/[*.js]'></script>

 

 

 

<server.js>

var express = require('express');
var app = express();
var http = require('http').Server(app);   


// server.js의 실행경로 + '/js'를 localhost:port/js로 마운트
app.use('/js', express.static(__dirname + '/js'));


app.get('/',function(req, res){  
  res.sendFile(__dirname + '/client.html');
});


http.listen(3000, function(){
  console.log('server on!');
});

 

 

<client.html>

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <script src="http://[server_ip]:[port]/js/jquery-1.11.1.js"></script>
    <!--외부의 jquery-1.11.1.js 파일을 포함시킬 수 있다.-->
  </head>
  <body>
   	...
  </body>
</html>

 

 

    '프로그래밍' 카테고리의 다른 글
    • [CSS] <li> 태그에서 float속성 right일 때 행 나누는 방법
    • [Node.js] Socket.io 나를 제외한 모든 클라이언트에게 전송
    • [Python] openpyxl 모듈을 이용한 엑셀(Excel) 데이터 가져오기
    • [SQLite] CONSTRAINT - 제약조건 추가/변경/삭제
    e_yejun
    e_yejun
    정리노트 •_•

    티스토리툴바