Skip to content

Commit 03d41e5

Browse files
Add React SSR demo with Micronaut and GraalJS
1 parent 0951909 commit 03d41e5

File tree

24 files changed

+6192
-0
lines changed

24 files changed

+6192
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Test GraalJS React SSR with Micronaut
2+
3+
on:
4+
push:
5+
paths:
6+
- 'graaljs/graaljs-react-ssr/**'
7+
- '.github/workflows/graaljs-react-ssr.yml'
8+
pull_request:
9+
paths:
10+
- 'graaljs/graaljs-react-ssr/**'
11+
- '.github/workflows/graaljs-react-ssr.yml'
12+
workflow_dispatch:
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
run:
19+
name: 'graaljs-react-ssr'
20+
runs-on: ubuntu-latest
21+
timeout-minutes: 30
22+
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- uses: graalvm/setup-graalvm@v1
27+
with:
28+
java-version: '24.0.0'
29+
distribution: 'graalvm'
30+
github-token: ${{ secrets.GITHUB_TOKEN }}
31+
cache: 'maven'
32+
33+
- name: Build and run Micronaut app
34+
run: |
35+
cd graaljs/graaljs-react-ssr
36+
./mvnw clean package -DskipTests
37+
./mvnw mn:run &
38+
39+
- name: Verify application is running
40+
run: |
41+
sleep 30
42+
curl --fail-with-body --silent --dump-header - -o /dev/null http://localhost:8080

graaljs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This directory contains demo applications and guides for [GraalJS](https://www.g
77
## Demos
88

99
- [Minimal Java application that embeds GraalJS](graaljs-starter/)
10+
- [Server-side rendering (SSR) of React.js charts in Micronaut using GraalJS](graaljs-react-ssr/)
1011

1112
## Guides
1213

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Thumbs.db
2+
.DS_Store
3+
.gradle
4+
build/
5+
target/
6+
out/
7+
.micronaut/
8+
.idea
9+
*.iml
10+
*.ipr
11+
*.iws
12+
.project
13+
.settings
14+
.classpath
15+
.factorypath
16+
src/js/node_modules
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
18+
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# React.js SSR with Micronaut
2+
3+
This project demonstrates how to implement **Server-Side Rendering (SSR)** of **[React.js](https://reactjs.org/)** components within a **[Micronaut](https://micronaut.io/)** application using **[GraalJS](https://www.graalvm.org/latest/reference-manual/js/)**. It uses the **[Recharts](https://recharts.org/en-US/)** library to generate interactive charts that are rendered on the server and returned as HTML.
4+
5+
## Prerequisites
6+
7+
Before you begin, make sure you have the following installed:
8+
9+
* A bit of time to explore and experiment 🙂
10+
* Your favorite text editor or IDE
11+
* JDK 21 or later
12+
* Maven 3.9.9 or later
13+
14+
## Installation Steps
15+
16+
1. **Clone the repository:**
17+
18+
```bash
19+
git clone https://github.com/graalvm/graal-languages-demos.git
20+
cd graaljs/graaljs-react-ssr
21+
```
22+
23+
2. **Build and run the Micronaut application:**
24+
25+
```bash
26+
./mvnw mn:run
27+
```
28+
29+
---
30+
31+
## Result
32+
33+
Open your browser and go to [http://localhost:8080](http://localhost:8080) to view the server-rendered React charts. The charts are generated on the server and returned as HTML, providing fast initial page load and improved performance.
34+
35+
---
36+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# AOT configuration properties for jar packaging
2+
# Please review carefully the optimizations enabled below
3+
# Check https://micronaut-projects.github.io/micronaut-aot/latest/guide/ for more details
4+
5+
# Caches environment property values: environment properties will be deemed immutable after application startup.
6+
cached.environment.enabled=true
7+
8+
# Precomputes Micronaut configuration property keys from the current environment variables
9+
precompute.environment.properties.enabled=true
10+
11+
# Replaces logback.xml with a pure Java configuration
12+
logback.xml.to.java.enabled=true
13+
14+
# Converts YAML configuration files to Java configuration
15+
yaml.to.java.config.enabled=true
16+
17+
# Scans for service types ahead-of-time, avoiding classpath scanning at startup
18+
serviceloading.jit.enabled=true
19+
20+
# Scans reactive types at build time instead of runtime
21+
scan.reactive.types.enabled=true
22+
23+
# Deduces the environment at build time instead of runtime
24+
deduce.environment.enabled=true
25+
26+
# Checks for the existence of some types at build time instead of runtime
27+
known.missing.types.enabled=true
28+
29+
# Precomputes property sources at build time
30+
sealed.property.source.enabled=true
31+
32+
# The list of service types to be scanned (comma separated)
33+
service.types=io.micronaut.context.env.PropertySourceLoader,io.micronaut.inject.BeanConfiguration,io.micronaut.inject.BeanDefinitionReference,io.micronaut.http.HttpRequestFactory,io.micronaut.http.HttpResponseFactory,io.micronaut.core.beans.BeanIntrospectionReference,io.micronaut.core.convert.TypeConverterRegistrar,io.micronaut.context.env.PropertyExpressionResolver
34+
35+
# A list of types that the AOT analyzer needs to check for existence (comma separated)
36+
known.missing.types.list=io.reactivex.Observable,reactor.core.publisher.Flux,kotlinx.coroutines.flow.Flow,io.reactivex.rxjava3.core.Flowable,io.reactivex.rxjava3.core.Observable,io.reactivex.Single,reactor.core.publisher.Mono,io.reactivex.Maybe,io.reactivex.rxjava3.core.Single,io.reactivex.rxjava3.core.Maybe,io.reactivex.Completable,io.reactivex.rxjava3.core.Completable,io.methvin.watchservice.MacOSXListeningWatchService,io.micronaut.core.async.publisher.CompletableFuturePublisher,io.micronaut.core.async.publisher.Publishers.JustPublisher,io.micronaut.core.async.subscriber.Completable
37+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
applicationType: default
2+
defaultPackage: com.example
3+
testFramework: junit
4+
sourceLanguage: java
5+
buildTool: maven
6+
features: [app-name, http-client-test, java, java-application, junit, logback, maven, maven-enforcer-plugin, micronaut-aot, micronaut-http-validation, netty-server, properties, readme, serialization-jackson, shade, static-resources, views-react]

0 commit comments

Comments
 (0)