본문 바로가기

Server Programming/Spring Boot Full-Stack Programming

[스프링 풀스택 클론 코딩] Node.js (npm) 연동

반응형

Node.js 설치 후

프로젝트의 /static 경로에 npm init을 이용해 부트스트랩을 설치한다.

cd spring_dev/main/src/resources/static
npm init
npm install bootstrap
npm install jquery --save

 

.gitignore

##NPM##
src/main/resources/static/node_modules
src/main/resources/static/node

 

-> 업데이트를 안하도록 설정

 

빌드 설정

-> 메이븐 빌드시, static 디렉토리에 있는 package.json도 빌드하도록

<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.8.0</version>
<configuration>
<nodeVersion>v4.6.0</nodeVersion>
<workingDirectory>src/main/resources/static</workingDirectory>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<phase>generate-resources</phase>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal></goals>
<phase>generate-resources</phase>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
</executions>
</plugin>

 

스프링 시큐리티

모듈 요청에 보안을 적용하므로 허용해줘야한다.

@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring()
.mvcMatchers("/node_modules/**")
.requestMatchers(PathRequest.toStaticResources().atCommonLocations());
}

-> 시큐리티 버전업으로 인한 빈즈로 만들어줘야함

@Bean
	public WebSecurityCustomizer webSecurityCustomizer() {
		// static리소스도 요청을 거부하지 않는다.
		return (web) -> web.ignoring().mvcMatchers("/node_modules/**")
				.requestMatchers(PathRequest.toStaticResources().atCommonLocations());
	}

 

반응형