Created
February 23, 2020 14:55
-
-
Save mariomartinezricston/3bc434e3d916a0431d25df04d46daea9 to your computer and use it in GitHub Desktop.
Serve react app gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ee:transform doc:name="pathToRead"> | |
<ee:message></ee:message> | |
<ee:variables> | |
<ee:set-variable variableName="readFilePath" ><![CDATA[%dw 2.0 | |
output text/plain | |
var webURLPatterns = '((\/ui\/?)+\$)|(\/ui\/messages)' | |
fun isWebRequest(requestedPath) = | |
sizeOf(requestedPath match(webURLPatterns)) > 0 | |
fun removeUIPrefix(requestedPath) = | |
(requestedPath replace /^(\/ui\/)/ with "") | |
--- | |
using( webRequest = isWebRequest(attributes.requestPath) ) | |
(if(webRequest) | |
'/web/index.html' | |
else | |
"/web/" ++ removeUIPrefix(attributes.requestPath) )]]></ee:set-variable> | |
</ee:variables> | |
</ee:transform> | |
<ee:transform doc:name="read file"> | |
<ee:message> | |
<ee:set-payload><![CDATA[%dw 2.0 | |
import java!org::mule::runtime::core::api::util::IOUtils | |
output text/plain | |
--- | |
IOUtils::getResourceAsStream(vars.readFilePath, null)]]></ee:set-payload> | |
</ee:message> | |
</ee:transform> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<groupId>com.github.eirslett</groupId> | |
<artifactId>frontend-maven-plugin</artifactId> | |
<version>1.9.1</version> | |
<configuration> | |
<workingDirectory>${basedir}/ui/mule-welcomer</workingDirectory> | |
</configuration> | |
<executions> | |
<!-- install node.js libraries in your build process without | |
installing Node/NPM globally for your build system --> | |
<execution> | |
<id>install node and npm</id> | |
<goals> | |
<goal>install-node-and-npm</goal> | |
</goals> | |
<configuration> | |
<nodeVersion>v12.14.1</nodeVersion> | |
<npmVersion>6.13.4</npmVersion> | |
</configuration> | |
</execution> | |
<execution> | |
<id>build</id> | |
<goals> | |
<goal>npm</goal> | |
</goals> | |
<configuration> | |
<arguments>run-script build</arguments> | |
</configuration> | |
<phase>generate-resources</phase> | |
</execution> | |
</executions> | |
</plugin> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<http:listener-config name="mule-welcomer-httpListenerConfig"> | |
<http:listener-connection host="0.0.0.0" port="8081" /> | |
<http:listener-interceptors> | |
<http:cors-interceptor allowCredentials="false"> | |
<http:origins> | |
<http:public-resource /> | |
</http:origins> | |
</http:cors-interceptor> | |
</http:listener-interceptors> | |
</http:listener-config> | |
<http:listener doc:name="Listener" config-ref="mule-welcomer-httpListenerConfig" path="/ui/*"> | |
<http:listener config-ref="mule-welcomer-httpListenerConfig" path="/api/*"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<profiles> | |
<profile> | |
<id>default</id> | |
<activation> | |
<activeByDefault>true</activeByDefault> | |
</activation> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>com.github.eirslett</groupId> | |
<artifactId>frontend-maven-plugin</artifactId> | |
<version>1.9.1</version> | |
<configuration> | |
<workingDirectory>${basedir}/ui/mule-welcomer</workingDirectory> | |
</configuration> | |
<executions> | |
<execution> | |
<id>build</id> | |
<goals> | |
<goal>npm</goal> | |
</goals> | |
<configuration> | |
<arguments>run-script build</arguments> | |
</configuration> | |
<phase>generate-resources</phase> | |
</execution> | |
</executions> | |
</plugin> | |
</plugins> | |
</build> | |
</profile> | |
<profile> | |
<id>install-npm</id> | |
<activation> | |
<property> | |
<name>installNPM</name> | |
</property> | |
</activation> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>com.github.eirslett</groupId> | |
<artifactId>frontend-maven-plugin</artifactId> | |
<version>1.9.1</version> | |
<configuration> | |
<workingDirectory>${basedir}/ui/mule-welcomer</workingDirectory> | |
</configuration> | |
<executions> | |
<execution> | |
<id>install node and npm</id> | |
<goals> | |
<goal>install-node-and-npm</goal> | |
</goals> | |
<configuration> | |
<!-- See https://nodejs.org/en/download/ for latest node and npm | |
(lts) versions --> | |
<nodeVersion>v12.14.1</nodeVersion> | |
<npmVersion>6.13.4</npmVersion> | |
</configuration> | |
</execution> | |
<execution> | |
<id>npm install</id> | |
<goals> | |
<goal>npm</goal> | |
</goals> | |
<configuration> | |
<arguments>install</arguments> | |
</configuration> | |
</execution> | |
<execution> | |
<id>build</id> | |
<goals> | |
<goal>npm</goal> | |
</goals> | |
<configuration> | |
<arguments>run-script build</arguments> | |
</configuration> | |
<phase>generate-resources</phase> | |
</execution> | |
</executions> | |
</plugin> | |
</plugins> | |
</build> | |
</profile> | |
</profiles> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<build> | |
.... | |
<resources> | |
<resource> | |
<directory>ui/mule-welcomer/build</directory> | |
</resource> | |
<resource> | |
<directory>src/main/resources</directory> | |
</resource> | |
</resources> | |
</build> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<http:load-static-resource doc:name="Load static resource" resourceBasePath="#[p('app.home') ++ '/web']"/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment