PromucFlow_constructor/app/client/packages/rts/src/server.ts
Valera Melnikov 9f607d250d
chore: move local dependency to packages (#23395)
## Description
1. Move everything related to client from app folder to client folder
(`.yarn`, `yarn.lock`, package.json, .gitignore)
2. Move `ast` and `rst` to client packages
3. Fix running scripts in packages
4. Add running unit tests in packages in CI

TODO: It is necessary to consider enabling the `nmHoistingLimits:
workspaces` option, since now all packages are hoisted to the root,
there may be issues with dependencies in workspaces. Also, there is a
possibility of implicit use of packages.

https://yarnpkg.com/configuration/yarnrc#nmHoistingLimits

#### PR fixes following issue(s)
Fixes #23333

#### Type of change
- Chore (housekeeping or task changes that don't impact user perception)

## Testing

#### How Has This Been Tested?
- [x] Manual
- [x] Jest
- [x] Cypress

## Checklist:
#### Dev activity
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag

Co-authored-by: Valera Melnikov <melnikov.vv@greendatasoft.ru>
2023-05-22 15:55:46 +03:00

62 lines
1.7 KiB
TypeScript

import http from "http";
import path from "path";
import express from "express";
import { Server } from "socket.io";
import type { LogLevelDesc } from "loglevel";
import log from "loglevel";
import { VERSION as buildVersion } from "./version"; // release version of the api
import { initializeSockets } from "./sockets";
// routes
import ast_routes from "./routes/ast_routes";
import health_check_routes from "./routes/health_check_routes";
const RTS_BASE_PATH = "/rts";
export const RTS_BASE_API_PATH = "/rts-api/v1";
// Setting the logLevel for all log messages
const logLevel: LogLevelDesc = (process.env.APPSMITH_LOG_LEVEL ||
"debug") as LogLevelDesc;
log.setLevel(logLevel);
const API_BASE_URL = process.env.APPSMITH_API_BASE_URL;
if (API_BASE_URL == null || API_BASE_URL === "") {
log.error("Please provide a valid value for `APPSMITH_API_BASE_URL`.");
process.exit(1);
}
const APPSMITH_RTS_PORT = process.env.APPSMITH_RTS_PORT || 8091;
//Disable x-powered-by header to prevent information disclosure
const app = express();
app.disable("x-powered-by");
const server = new http.Server(app);
const io = new Server(server, {
path: RTS_BASE_PATH,
});
// Initializing Sockets
initializeSockets(io);
// parse incoming json requests
app.use(express.json({ limit: "5mb" }));
// Initializing Routes
app.use(express.static(path.join(__dirname, "static")));
app.get("/", (_, res) => {
res.redirect("/index.html");
});
app.use(`${RTS_BASE_API_PATH}/ast`, ast_routes);
app.use(`${RTS_BASE_API_PATH}`, health_check_routes);
server.headersTimeout = 61000;
server.keepAliveTimeout = 60000;
// Run the server
server.listen(APPSMITH_RTS_PORT, () => {
log.info(
`RTS version ${buildVersion} running at http://localhost:${APPSMITH_RTS_PORT}`,
);
});
export default server;