chore: resolve shared import problem in production
move everything into packages
This commit is contained in:
parent
d912c788c5
commit
486587f232
@ -17,7 +17,7 @@ RUN pnpm build
|
||||
RUN pip install apprise --break-system-packages
|
||||
|
||||
# remove unused source file
|
||||
RUN rm -rf ./src
|
||||
RUN rm -rf ./src/client
|
||||
RUN rm -rf ./website
|
||||
RUN rm -rf ./reporter
|
||||
|
||||
|
@ -6,8 +6,9 @@
|
||||
"dev": "concurrently --kill-others npm:dev:server npm:dev:web",
|
||||
"dev:web": "cd src/client && pnpm dev",
|
||||
"dev:server": "cd src/server && pnpm dev",
|
||||
"start": "cross-env NODE_ENV=production node ./dist/src/server/main.js",
|
||||
"start:docker": "pnpm db:migrate:apply && pnpm db:generate && pnpm start",
|
||||
"start": "cd src/server && cross-env NODE_ENV=production node ./dist/src/server/main.js",
|
||||
"start:docker": "pnpm start:docker:db && pnpm start",
|
||||
"start:docker:db": "cd src/server && pnpm db:migrate:apply",
|
||||
"test": "vitest",
|
||||
"build": "pnpm build:tracker && pnpm build:server && pnpm build:client && pnpm build:geo",
|
||||
"build:client": "cd src/client && pnpm build",
|
||||
|
@ -7,7 +7,10 @@ import { keyBy } from 'lodash-es';
|
||||
|
||||
interface StatusPageServicesProps {
|
||||
workspaceId: string;
|
||||
monitorList: PrismaJson.MonitorStatusPageList;
|
||||
monitorList: {
|
||||
id: string;
|
||||
showCurrent?: boolean;
|
||||
}[];
|
||||
}
|
||||
export const StatusPageServices: React.FC<StatusPageServicesProps> = React.memo(
|
||||
(props) => {
|
||||
|
@ -6,7 +6,7 @@ export default defineConfig({
|
||||
root: __dirname,
|
||||
plugins: [react()],
|
||||
build: {
|
||||
outDir: '../../dist/src/server/public',
|
||||
outDir: '../server/public',
|
||||
},
|
||||
clearScreen: false,
|
||||
server: {
|
||||
|
@ -25,6 +25,7 @@ import { initCronjob } from './cronjob';
|
||||
import { logger } from './utils/logger';
|
||||
import { monitorRouter } from './router/monitor';
|
||||
import { healthRouter } from './router/health';
|
||||
import path from 'path';
|
||||
|
||||
const port = env.port;
|
||||
|
||||
@ -44,7 +45,7 @@ app.use(express.json());
|
||||
app.use(passport.initialize());
|
||||
app.use(morgan('tiny'));
|
||||
app.use(cors());
|
||||
app.use(express.static('dist'));
|
||||
app.use(express.static('public'));
|
||||
|
||||
// http://expressjs.com/en/advanced/best-practice-security.html#at-a-minimum-disable-x-powered-by-header
|
||||
app.disable('x-powered-by');
|
||||
@ -71,6 +72,13 @@ if (env.allowOpenapi) {
|
||||
app.use('/open', trpcOpenapiHttpHandler);
|
||||
}
|
||||
|
||||
// fallback
|
||||
app.get('/*', (req, res) => {
|
||||
if (req.accepts('html')) {
|
||||
res.sendFile(path.join(process.cwd(), 'public', 'index.html'));
|
||||
}
|
||||
});
|
||||
|
||||
app.use((err: any, req: any, res: any, next: any) => {
|
||||
logger.error(err);
|
||||
res.status(500).json({ message: err.message });
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { z } from 'zod';
|
||||
import { schemas } from '../../../types';
|
||||
|
||||
// Match prisma `JsonValue`
|
||||
export const jsonFieldSchema = z.union([
|
||||
|
12
src/server/model/_schema/monitor.ts
Normal file
12
src/server/model/_schema/monitor.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { MonitorInfo } from '../../../types';
|
||||
import { MonitorModelSchema } from '../../prisma/zod';
|
||||
|
||||
export type MonitorInfoWithNotificationIds = MonitorInfo & {
|
||||
notifications: { id: string }[];
|
||||
};
|
||||
|
||||
export const MonitorPublicInfoSchema = MonitorModelSchema.pick({
|
||||
id: true,
|
||||
name: true,
|
||||
type: true,
|
||||
});
|
@ -1,5 +1,5 @@
|
||||
import { MonitorPublicInfoSchema } from '../../../types';
|
||||
import { prisma } from '../_client';
|
||||
import { MonitorPublicInfoSchema } from '../_schema/monitor';
|
||||
import { MonitorManager } from './manager';
|
||||
|
||||
export const monitorManager = new MonitorManager();
|
||||
|
@ -3,14 +3,11 @@ import { body, header, param, validate } from '../middleware/validate';
|
||||
import { recordServerStatus } from '../model/serverStatus';
|
||||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import { env } from '../utils/env';
|
||||
|
||||
export const serverStatusRouter = Router();
|
||||
|
||||
const installScript = fs.readFileSync(
|
||||
env.isProd
|
||||
? path.resolve(process.cwd(), './scripts/install.sh')
|
||||
: path.resolve(process.cwd(), '../../scripts/install.sh')
|
||||
path.resolve(process.cwd(), '../../scripts/install.sh')
|
||||
);
|
||||
|
||||
serverStatusRouter.post(
|
||||
|
@ -13,10 +13,6 @@ import {
|
||||
getMonitorRecentData,
|
||||
monitorManager,
|
||||
} from '../../model/monitor';
|
||||
import {
|
||||
MonitorInfoWithNotificationIds,
|
||||
MonitorPublicInfoSchema,
|
||||
} from '../../../types';
|
||||
import dayjs from 'dayjs';
|
||||
import {
|
||||
monitorEventSchema,
|
||||
@ -29,6 +25,10 @@ import { OpenApiMeta } from 'trpc-openapi';
|
||||
import { MonitorStatusPageModelSchema } from '../../prisma/zod';
|
||||
import { runCodeInVM } from '../../model/monitor/provider/custom';
|
||||
import { createAuditLog } from '../../model/auditLog';
|
||||
import {
|
||||
MonitorInfoWithNotificationIds,
|
||||
MonitorPublicInfoSchema,
|
||||
} from '../../model/_schema/monitor';
|
||||
|
||||
export const monitorRouter = router({
|
||||
all: workspaceProcedure
|
||||
|
@ -4,7 +4,7 @@
|
||||
"exclude": ["node_modules/**/*", "dist"],
|
||||
"compilerOptions": {
|
||||
"rootDirs": ["./", "../"],
|
||||
"outDir": "../../dist",
|
||||
"outDir": "./dist",
|
||||
"noEmit": false
|
||||
}
|
||||
}
|
||||
|
10
src/server/types/global.d.ts
vendored
10
src/server/types/global.d.ts
vendored
@ -1,7 +1,17 @@
|
||||
import type { JWTPayload } from '../middleware/auth';
|
||||
import type { MonitorStatusPageListSchema } from '../prisma/zod/schemas';
|
||||
|
||||
declare global {
|
||||
namespace Express {
|
||||
interface User extends JWTPayload {}
|
||||
}
|
||||
|
||||
namespace PrismaJson {
|
||||
type CommonPayload = Record<string, any>;
|
||||
type DashboardLayout = {
|
||||
layouts: Record<string, any[]>;
|
||||
items: any[];
|
||||
} | null;
|
||||
type MonitorStatusPageList = z.infer<typeof MonitorStatusPageListSchema>;
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +0,0 @@
|
||||
import packageJson from '../../package.json';
|
||||
|
||||
export const version = packageJson.version;
|
@ -3,8 +3,17 @@
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"description": "",
|
||||
"main": "index.ts",
|
||||
"scripts": {},
|
||||
"types": "./dist/cjs/src/shared/src/index.d.ts",
|
||||
"exports": {
|
||||
"import": "./dist/esm/src/shared/src/index.js",
|
||||
"require": "./dist/cjs/src/shared/src/index.js"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "pnpm build:cjs && pnpm build:esm",
|
||||
"build:cjs": "tsc --module commonjs --outDir ./dist/cjs",
|
||||
"build:esm": "tsc --module esnext --outDir ./dist/esm",
|
||||
"postinstall": "pnpm build"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "moonrailgun <moonrailgun@gmail.com>",
|
||||
"dependencies": {
|
||||
|
3
src/shared/src/config.ts
Normal file
3
src/shared/src/config.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import packageJson from '../../../package.json';
|
||||
|
||||
export const version = packageJson.version;
|
@ -1,4 +1,4 @@
|
||||
import { ServerStatusInfo } from '../types';
|
||||
import type { ServerStatusInfo } from '../../types';
|
||||
|
||||
export function isServerOnline(info: ServerStatusInfo): boolean {
|
||||
return new Date(info.updatedAt).valueOf() + info.timeout * 1000 > Date.now();
|
10
src/shared/tsconfig.json
Normal file
10
src/shared/tsconfig.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist",
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"noEmit": false
|
||||
},
|
||||
"include": ["./src/**/*"]
|
||||
}
|
@ -1,18 +1,3 @@
|
||||
import { z } from 'zod';
|
||||
import { MonitorStatusPageListSchema } from '../server/prisma/zod/schemas';
|
||||
|
||||
export * as schemas from '../server/prisma/zod/index';
|
||||
export * from './server';
|
||||
export * from './monitor';
|
||||
export * from './utils';
|
||||
|
||||
declare global {
|
||||
namespace PrismaJson {
|
||||
type CommonPayload = Record<string, any>;
|
||||
type DashboardLayout = {
|
||||
layouts: Record<string, any[]>;
|
||||
items: any[];
|
||||
} | null;
|
||||
type MonitorStatusPageList = z.infer<typeof MonitorStatusPageListSchema>;
|
||||
}
|
||||
}
|
||||
export type * from './server';
|
||||
export type * from './monitor';
|
||||
export type * from './utils';
|
||||
|
@ -1,6 +1,5 @@
|
||||
import type { MonitorModelSchema } from '../server/prisma/zod';
|
||||
import { ExactType } from './utils';
|
||||
import { schemas } from '.';
|
||||
import z from 'zod';
|
||||
|
||||
type Monitor = z.infer<typeof MonitorModelSchema>;
|
||||
@ -11,13 +10,3 @@ export type MonitorInfo = ExactType<
|
||||
payload: Record<string, any>;
|
||||
}
|
||||
>;
|
||||
|
||||
export type MonitorInfoWithNotificationIds = MonitorInfo & {
|
||||
notifications: { id: string }[];
|
||||
};
|
||||
|
||||
export const MonitorPublicInfoSchema = schemas.MonitorModelSchema.pick({
|
||||
id: true,
|
||||
name: true,
|
||||
type: true,
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user