Skip to content

Commit 26e3bb2

Browse files
committed
Add documentation files and update configuration for Docs service
1 parent bee3855 commit 26e3bb2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+4924
-3
lines changed

.vscode/launch.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@
105105
"restart": true,
106106
"autoAttachChildProcesses": true
107107
},
108+
{
109+
"address": "127.0.0.1",
110+
"localRoot": "${workspaceFolder}/Worker",
111+
"name": "Docs: Debug with Docker",
112+
"port": 8738,
113+
"remoteRoot": "/usr/src/app",
114+
"request": "attach",
115+
"skipFiles": [
116+
"<node_internals>/**"
117+
],
118+
"type": "node",
119+
"restart": true,
120+
"autoAttachChildProcesses": true
121+
},
108122
{
109123
"address": "127.0.0.1",
110124
"localRoot": "${workspaceFolder}/Worker",

App/Index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import BaseAPIRoutes from "./FeatureSet/BaseAPI/Index";
2-
import DocsRoutes from "./FeatureSet/Docs/Index";
2+
import DocsRoutes from "../Docs/Routes";
33
// import FeatureSets.
44
import IdentityRoutes from "./FeatureSet/Identity/Index";
55
import NotificationRoutes from "./FeatureSet/Notification/Index";

Docs/.dockerignore

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
.git
2+
3+
node_modules
4+
# See https://help.github.com/ignore-files/ for more about ignoring files.
5+
6+
# dependencies
7+
/node_modules
8+
node_modules
9+
10+
.idea
11+
# testing
12+
/coverage
13+
14+
# production
15+
/build
16+
17+
# misc
18+
.DS_Store
19+
20+
env.js
21+
22+
npm-debug.log*
23+
yarn-debug.log*
24+
yarn-error.log*
25+
26+
yarn.lock
27+
Untitled-1
28+
*.local.sh
29+
*.local.yaml
30+
run
31+
stop
32+
33+
nohup.out*
34+
35+
encrypted-credentials.tar
36+
encrypted-credentials/
37+
38+
_README.md
39+
40+
# Important Add production values to gitignore.
41+
values-saas-production.yaml
42+
kubernetes/values-saas-production.yaml
43+
44+
/private
45+
46+
/tls_cert.pem
47+
/tls_key.pem
48+
/keys
49+
50+
temp_readme.md
51+
52+
tests/coverage
53+
54+
settings.json
55+
56+
GoSDK/tester/

Docs/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.js text eol=lf

Docs/.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# See https://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# dependencies
4+
#/backend/node_modules
5+
/kubernetes
6+
/node_modules
7+
.idea
8+
9+
# misc
10+
.DS_Store
11+
12+
13+
npm-debug.log*
14+
yarn-debug.log*
15+
yarn-error.log*
16+
yarn.lock
17+
18+
**/*/paymentService.test.js
19+
apiTest.rest
20+
21+
application_security_dir
22+
container_security_dir
23+
24+
# coverage
25+
/coverage
26+
/.nyc_output
27+
28+
/greenlock.d/config.json
29+
/greenlock.d/config.json.bak
30+
/.greenlockrc

Docs/Database/read-only-db-user.sql

Lines changed: 0 additions & 2 deletions
This file was deleted.

Docs/Dockerfile.tpl

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#
2+
# OneUptime-App Dockerfile
3+
#
4+
5+
# Pull base image nodejs image.
6+
FROM node:21.2-alpine3.18
7+
RUN mkdir /tmp/npm && chmod 2777 /tmp/npm && chown 1000:1000 /tmp/npm && npm config set cache /tmp/npm --global
8+
9+
RUN npm config set fetch-retries 5
10+
RUN npm config set fetch-retry-mintimeout 100000
11+
RUN npm config set fetch-retry-maxtimeout 600000
12+
13+
14+
15+
ARG GIT_SHA
16+
ARG APP_VERSION
17+
18+
ENV GIT_SHA=${GIT_SHA}
19+
ENV APP_VERSION=${APP_VERSION}
20+
21+
22+
# IF APP_VERSION is not set, set it to 1.0.0
23+
RUN if [ -z "$APP_VERSION" ]; then export APP_VERSION=1.0.0; fi
24+
25+
26+
# Install bash.
27+
RUN apk add bash && apk add curl
28+
29+
30+
# Install python
31+
RUN apk update && apk add --no-cache --virtual .gyp python3 make g++
32+
33+
#Use bash shell by default
34+
SHELL ["/bin/bash", "-c"]
35+
36+
37+
RUN mkdir /usr/src
38+
39+
WORKDIR /usr/src/Common
40+
COPY ./Common/package*.json /usr/src/Common/
41+
# Set version in ./Common/package.json to the APP_VERSION
42+
RUN sed -i "s/\"version\": \".*\"/\"version\": \"$APP_VERSION\"/g" /usr/src/Common/package.json
43+
RUN npm install
44+
COPY ./Common /usr/src/Common
45+
46+
ENV PRODUCTION=true
47+
48+
WORKDIR /usr/src/app
49+
50+
# Install app dependencies
51+
COPY ./Docs/package*.json /usr/src/app/
52+
# Set version in ./App/package.json to the APP_VERSION
53+
RUN sed -i "s/\"version\": \".*\"/\"version\": \"$APP_VERSION\"/g" /usr/src/app/package.json
54+
RUN npm install
55+
56+
# Expose ports.
57+
# - 1447: OneUptime-Docs
58+
EXPOSE 1447
59+
60+
{{ if eq .Env.ENVIRONMENT "development" }}
61+
#Run the app
62+
CMD [ "npm", "run", "dev" ]
63+
{{ else }}
64+
# Copy app source
65+
COPY ./Docs /usr/src/app
66+
# Bundle app source
67+
RUN npm run compile
68+
#Run the app
69+
CMD [ "npm", "start" ]
70+
{{ end }}

Docs/Index.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import DocsRoutes from "./Routes";
2+
import { PromiseVoidFunction } from "Common/Types/FunctionTypes";
3+
import InfrastructureStatus from "Common/Server/Infrastructure/Status";
4+
import logger from "Common/Server/Utils/Logger";
5+
import App from "Common/Server/Utils/StartServer";
6+
import Telemetry from "Common/Server/Utils/Telemetry";
7+
import "ejs";
8+
9+
const APP_NAME: string = "docs";
10+
11+
const init: PromiseVoidFunction = async (): Promise<void> => {
12+
try {
13+
// Initialize telemetry
14+
Telemetry.init({
15+
serviceName: APP_NAME,
16+
});
17+
18+
const statusCheck: PromiseVoidFunction = async (): Promise<void> => {
19+
// Check the status of infrastructure components
20+
return await InfrastructureStatus.checkStatus({
21+
checkClickhouseStatus: false,
22+
checkPostgresStatus: false,
23+
checkRedisStatus: false,
24+
});
25+
};
26+
27+
// Initialize the app with service name and status checks
28+
await App.init({
29+
appName: APP_NAME,
30+
statusOptions: {
31+
liveCheck: statusCheck,
32+
readyCheck: statusCheck,
33+
},
34+
});
35+
36+
await DocsRoutes.init();
37+
38+
// Add default routes to the app
39+
await App.addDefaultRoutes();
40+
} catch (err) {
41+
logger.error("App Init Failed:");
42+
logger.error(err);
43+
throw err;
44+
}
45+
};
46+
47+
init().catch((err: Error) => {
48+
logger.error(err);
49+
logger.error("Exiting node process");
50+
process.exit(1);
51+
});

Docs/README.md

Lines changed: 29 additions & 0 deletions

Docs/Routes copy.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import AuthenticationServiceHandler from "./Service/Authentication";
2+
import DataTypeServiceHandler from "./Service/DataType";
3+
import ErrorServiceHandler from "./Service/Errors";
4+
import IntroductionServiceHandler from "./Service/Introduction";
5+
import ModelServiceHandler from "./Service/Model";
6+
import PageNotFoundServiceHandler from "./Service/PageNotFound";
7+
import PaginationServiceHandler from "./Service/Pagination";
8+
import PermissionServiceHandler from "./Service/Permissions";
9+
import StatusServiceHandler from "./Service/Status";
10+
import { StaticPath } from "./Utils/Config";
11+
import ResourceUtil, { ModelDocumentation } from "./Utils/Resources";
12+
import Dictionary from "Common/Types/Dictionary";
13+
import FeatureSet from "Common/Server/Types/FeatureSet";
14+
import Express, {
15+
ExpressApplication,
16+
ExpressRequest,
17+
ExpressResponse,
18+
ExpressStatic,
19+
} from "Common/Server/Utils/Express";
20+
21+
const APIReferenceFeatureSet: FeatureSet = {
22+
init: async (): Promise<void> => {
23+
const ResourceDictionary: Dictionary<ModelDocumentation> =
24+
ResourceUtil.getResourceDictionaryByPath();
25+
26+
const app: ExpressApplication = Express.getExpressApp();
27+
28+
// Serve static files for the API reference with a cache max age of 30 days
29+
app.use("/reference", ExpressStatic(StaticPath, { maxAge: 2592000 }));
30+
31+
// Redirect index page to the introduction page
32+
app.get(["/reference"], (_req: ExpressRequest, res: ExpressResponse) => {
33+
return res.redirect("/reference/introduction");
34+
});
35+
36+
// Handle "Page Not Found" page
37+
app.get(
38+
["/reference/page-not-found"],
39+
(req: ExpressRequest, res: ExpressResponse) => {
40+
return PageNotFoundServiceHandler.executeResponse(req, res);
41+
},
42+
);
43+
44+
// Handle all other pages based on the "page" parameter
45+
app.get(
46+
["/reference/:page"],
47+
(req: ExpressRequest, res: ExpressResponse) => {
48+
const page: string | undefined = req.params["page"];
49+
50+
if (!page) {
51+
return PageNotFoundServiceHandler.executeResponse(req, res);
52+
}
53+
54+
const currentResource: ModelDocumentation | undefined =
55+
ResourceDictionary[page];
56+
57+
// Execute the appropriate service handler based on the "page" parameter
58+
if (req.params["page"] === "permissions") {
59+
return PermissionServiceHandler.executeResponse(req, res);
60+
} else if (req.params["page"] === "authentication") {
61+
return AuthenticationServiceHandler.executeResponse(req, res);
62+
} else if (req.params["page"] === "pagination") {
63+
return PaginationServiceHandler.executeResponse(req, res);
64+
} else if (req.params["page"] === "errors") {
65+
return ErrorServiceHandler.executeResponse(req, res);
66+
} else if (req.params["page"] === "introduction") {
67+
return IntroductionServiceHandler.executeResponse(req, res);
68+
} else if (req.params["page"] === "status") {
69+
return StatusServiceHandler.executeResponse(req, res);
70+
} else if (req.params["page"] === "data-types") {
71+
return DataTypeServiceHandler.executeResponse(req, res);
72+
} else if (currentResource) {
73+
return ModelServiceHandler.executeResponse(req, res);
74+
}
75+
// page not found
76+
return PageNotFoundServiceHandler.executeResponse(req, res);
77+
},
78+
);
79+
80+
app.get("/reference/*", (req: ExpressRequest, res: ExpressResponse) => {
81+
return PageNotFoundServiceHandler.executeResponse(req, res);
82+
});
83+
},
84+
};
85+
86+
export default APIReferenceFeatureSet;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Docs/nodemon.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"watch": ["./","../Common/Server", "../Common/Types", "../Common/Utils", "../Common/Models"],
3+
"ext": "ts,json,tsx,env,js,jsx,hbs",
4+
"ignore": [
5+
"greenlock.d/*"
6+
],
7+
"exec": "node --inspect=0.0.0.0:9229 --require ts-node/register Index.ts"
8+
}

0 commit comments

Comments
 (0)