Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<packaging>pom</packaging>

<modules>
<module>smart-frontend</module>
<module>smart-maven-plugins</module>
<module>smart-common</module>
<module>smart-metrics</module>
Expand Down Expand Up @@ -102,6 +103,9 @@
<lombok-mapstruct-binding.version>0.2.0</lombok-mapstruct-binding.version>
<aspectj.version>1.9.22</aspectj.version>
<lombok.version>1.18.32</lombok.version>
<exec-maven-plugin.version>3.1.0</exec-maven-plugin.version>
<maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
<skip-build-web-ui>true</skip-build-web-ui>
</properties>

<profiles>
Expand Down Expand Up @@ -183,6 +187,13 @@
<activeByDefault>true</activeByDefault>
</activation>
</profile>

<profile>
<id>web-ui</id>
<properties>
<skip-build-web-ui>false</skip-build-web-ui>
</properties>
</profile>
</profiles>

<dependencyManagement>
Expand Down Expand Up @@ -714,6 +725,7 @@
<exclude>**/dist/**/*.js</exclude>
<exclude>**/local-repo/**/*.js</exclude>
<exclude>**/.tmp/**</exclude>
<exclude>**/build/assets/**</exclude>
</excludes>
</licenseSet>
</licenseSets>
Expand Down
2 changes: 2 additions & 0 deletions smart-frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
hash.txt
8 changes: 8 additions & 0 deletions smart-frontend/app/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

# Set Yarn version
YARN_VERSION=4.1.1

yarn set version $YARN_VERSION
yarn install
yarn build --mode production --outDir /wwwroot
5 changes: 5 additions & 0 deletions smart-frontend/build-prod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

CURDIR=$(dirname "$0")

docker run -i --rm -v $CURDIR/build:/wwwroot -v $CURDIR/app:/app -w /app node:20.9.0-alpine ./build.sh
34 changes: 34 additions & 0 deletions smart-frontend/check-and-build-prod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh

set -e

CURRENT_HASH="$(find ./app -type f -print0 | sort -z | xargs -0 sha1sum | sha1sum)"
if test -f hash.txt; then
PREV_HASH="$(cat hash.txt)"
fi

if test -f "build/index.html"; then
if [ "$PREV_HASH" = "$CURRENT_HASH" ]; then
echo "\033[0;90mWeb app has not changed\033[0m"
else
CURDIR=$(dirname "$0")
echo "\033[0;32mWeb app has changed\033[0m"
docker run -i --rm -v $CURDIR/build:/wwwroot -v $CURDIR/app:/app -w /app node:20.9.0-alpine ./build.sh
if [ -d "build" ]; then
echo "\033[0;34mWeb app has been built\033[0m"
echo "$CURRENT_HASH" >hash.txt
else
echo "\033[0;31mWeb app has not been built\033[0m"
fi
fi
else
echo "\033[0;31mWeb app has not been built\033[0m"
CURDIR=$(dirname "$0")
docker run -i --rm -v $CURDIR/build:/wwwroot -v $CURDIR/app:/app -w /app node:20.9.0-alpine ./build.sh
if [ -d "build" ]; then
echo "\033[0;34mWeb app has been built\033[0m"
echo "$CURRENT_HASH" >hash.txt
else
echo "\033[0;31mWeb app has not been built\033[0m"
fi
fi
61 changes: 61 additions & 0 deletions smart-frontend/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.smartdata</groupId>
<artifactId>smartdata-project</artifactId>
<version>1.6.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>smart-frontend</artifactId>
<version>1.6.0-SNAPSHOT</version>
<packaging>pom</packaging>

<build>
<plugins>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>${exec-maven-plugin.version}</version>
<executions>
<execution>
<id>Build ${project.artifactId} static resources</id>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<skip>${skip-build-web-ui}</skip>
<executable>/bin/bash</executable>
<arguments>
<argument>check-and-build-prod.sh</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
36 changes: 36 additions & 0 deletions smart-web-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<merged.api.spec.directory>${project.basedir}/src/main/resources/static</merged.api.spec.directory>
<openapi.codegen.output.dir>${project.basedir}</openapi.codegen.output.dir>
<openapi.codegen.package.base>org.smartdata.server.generated</openapi.codegen.package.base>
<ui.assets.directory>../smart-frontend/build/</ui.assets.directory>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -192,6 +193,41 @@
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin.version}</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>compile</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<skip>${skip-build-web-ui}</skip>
<outputDirectory>${project.build.directory}/classes/static</outputDirectory>
<resources>
<resource>
<directory>${ui.assets.directory}</directory>
<filtering>false</filtering>
<includes>
<include>**/*.woff2</include>
<include>**/*.ttf</include>
</includes>
</resource>
<resource>
<directory>${ui.assets.directory}</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/*.woff2</exclude>
<exclude>**/*.ttf</exclude>
</excludes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
@Configuration
public class SecurityConfiguration {
private static final String SESSION_COOKIE_NAME = "SSM_SESSIONID";
private static final String API_ENDPOINTS_PATTERN = "/api/**";

@Bean
@ConditionalOnProperty(name = ConfigKeys.WEB_SECURITY_ENABLED, havingValue = "true")
Expand All @@ -55,7 +56,7 @@ public SecurityFilterChain securityFilterChain(
List<SsmAuthHttpConfigurer> authHttpConfigurers) throws Exception {
baseHttpSecurity(http)
.authorizeRequests()
.antMatchers("/api/**").authenticated()
.antMatchers(API_ENDPOINTS_PATTERN).authenticated()
.and()
.anonymous().disable()
.addFilterAfter(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.smartdata.server.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class WebUiController {

@RequestMapping(value = "/**/{path:[^.]*}")
public String redirectToSpa() {
return "forward:/index.html";
}

}
10 changes: 10 additions & 0 deletions smart-web-server/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,13 @@ server:
session:
cookie:
name: SSM_SESSION_ID
spring:
web:
resources:
cache:
cachecontrol:
max-age: 3600
cache-private: true
mvc:
pathmatch:
matching-strategy: ant_path_matcher