Skip to content
Open
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
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ RUN mkdir /download && \
rm -rf /download && \
rm -rf /usr/local/tomcat/webapps/* && \
mkdir /usr/local/tomcat/webapps/ROOT && \
echo "<html><body>Nothing to see here</body></html>" > /usr/local/tomcat/webapps/ROOT/index.html
printf "<%% response.sendRedirect(\"/cwms-data/\"); %%>\n" > /usr/local/tomcat/webapps/ROOT/index.jsp && \
printf "User-agent: *\nAllow: /cwms-data/\nDisallow: /cwms-data/auth/\nDisallow: /cwms-data/catalog/\nDisallow: /cwms-data/timeseries/\nDisallow: /cwms-data/swagger-docs\nDisallow: /auth/\nSitemap: https://cwms-data.usace.army.mil/sitemap.xml\n" > /usr/local/tomcat/webapps/ROOT/robots.txt
CMD ["/usr/local/tomcat/bin/catalina.sh","run"]

FROM tomcat_base AS api

COPY --from=builder /builddir/cda-gui/dist/sitemap.xml /usr/local/tomcat/webapps/ROOT/sitemap.xml
COPY --from=builder /builddir/cwms-data-api/build/docker/cda/ /usr/local/tomcat
COPY --from=builder /builddir/cwms-data-api/build/docker/context.xml /usr/local/tomcat/conf
COPY --from=builder /builddir/cwms-data-api/build/docker/server.xml /usr/local/tomcat/conf
Expand Down
6 changes: 4 additions & 2 deletions cda-gui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ task buildGui(type:NpxTask) {
dependsOn npmInstall
command = "npm"
args = ["run", "build", "--prod"]
inputs.files('package.json', 'package-lock.json', 'vite.config.js')
inputs.files('package.json', 'package-lock.json', 'vite.config.js', 'index.html')
inputs.dir('src')
inputs.dir('public')
inputs.dir('scripts')
inputs.dir(fileTree("node_modules").exclude(".cache"))
outputs.dir('dist')
}
Expand Down Expand Up @@ -38,4 +40,4 @@ sourceSets {
}
}
}
}
}
2 changes: 1 addition & 1 deletion cda-gui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"build": "vite build && node scripts/generate-sitemap.mjs",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"prepare": "cd .. && husky cda-gui/.husky",
Expand Down
36 changes: 36 additions & 0 deletions cda-gui/scripts/generate-sitemap.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { mkdir, writeFile } from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";

import { sitemapPaths } from "../src/route-paths.js";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const projectDir = path.resolve(__dirname, "..");
const outputPath = path.join(projectDir, "dist", "sitemap.xml");

const siteOrigin = (process.env.SITE_ORIGIN ?? "https://cwms-data.usace.army.mil").replace(
/\/+$/,
"",
);
const siteBasePath = (process.env.SITE_BASE_PATH ?? "/cwms-data").replace(/\/+$/, "");

const urls = sitemapPaths.map((routePath) => {
const normalizedPath = routePath ? `/${routePath}` : "";
return `${siteOrigin}${siteBasePath}${normalizedPath}`;
});

const xml = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${urls
.map(
(url) => ` <url>
<loc>${url}</loc>
</url>`,
)
.join("\n")}
</urlset>
`;

await mkdir(path.dirname(outputPath), { recursive: true });
await writeFile(outputPath, xml, "utf8");
26 changes: 16 additions & 10 deletions cda-gui/src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,18 @@ import ErrorFallback from "./pages/ErrorFallback";
import FilterExpressions from "./pages/rsql";
import Timestamps from "./pages/timestamps";
import LegacyFormat from "./pages/legacy-format/index.jsx";
import { routePaths } from "./route-paths";

const queryClient = new QueryClient();
const routeComponents = {
home: Home,
"swagger-ui": SwaggerUI,
"data-query": DataQuery,
regexp: Regexp,
"filter-expressions": FilterExpressions,
timestamps: Timestamps,
"legacy-format": LegacyFormat,
};

const router = createBrowserRouter(
[
Expand All @@ -31,16 +41,12 @@ const router = createBrowserRouter(
element: <Layout />,
errorElement: <ErrorFallback />,
children: [
{ index: true, element: <Home /> },
{
path: "swagger-ui",
element: <SwaggerUI />,
},
{ path: "data-query", element: <DataQuery /> },
{ path: "regexp", element: <Regexp /> },
{ path: "filter-expressions", element: <FilterExpressions /> },
{ path: "timestamps", element: <Timestamps /> },
{ path: "legacy-format", element: <LegacyFormat /> },
...routePaths.map(({ id, index, path }) => {
const Component = routeComponents[id];
return index
? { index: true, element: <Component /> }
: { path, element: <Component /> };
}),
{ path: "*", element: <NotFound /> },
],
},
Expand Down
40 changes: 40 additions & 0 deletions cda-gui/src/route-paths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Routes are defined here to allow building a sitemap dynamically
export const routePaths = [
{
id: "home",
index: true,
sitemapPath: "",
},
{
id: "swagger-ui",
path: "swagger-ui",
sitemapPath: "swagger-ui",
},
{
id: "data-query",
path: "data-query",
sitemapPath: "data-query",
},
{
id: "regexp",
path: "regexp",
sitemapPath: "regexp",
},
{
id: "filter-expressions",
path: "filter-expressions",
sitemapPath: "filter-expressions",
},
{
id: "timestamps",
path: "timestamps",
sitemapPath: "timestamps",
},
{
id: "legacy-format",
path: "legacy-format",
sitemapPath: "legacy-format",
},
];

export const sitemapPaths = routePaths.map(({ sitemapPath }) => sitemapPath);
Loading