chore: improve dev env support

add websocket proxy in dev
add path diff between dev and prod
This commit is contained in:
moonrailgun 2024-01-28 16:40:15 +08:00
parent bb26196179
commit 70f0f56b47
5 changed files with 13 additions and 4 deletions

View File

@ -5,13 +5,13 @@
"scripts": {
"dev": "concurrently --kill-others npm:dev:server npm:dev:web",
"dev:web": "cd src/client && pnpm dev",
"dev:server": "pnpm run --filter @tianji/server 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",
"test": "vitest",
"build": "pnpm build:tracker && pnpm build:server && pnpm build:client && pnpm build:geo",
"build:client": "cd src/client && pnpm build",
"build:server": "pnpm run --filter @tianji/server build",
"build:server": "cd src/server && pnpm build",
"build:tracker": "ts-node scripts/build-tracker.ts",
"build:geo": "ts-node scripts/build-geo.ts",
"build:openapi": "ts-node scripts/build-openapi-schema.ts",

View File

@ -4,7 +4,7 @@ import type { SubscribeEventMap, SocketEventMap } from '../../server/ws/shared';
import { create } from 'zustand';
import { useEvent } from '../hooks/useEvent';
import { useEffect, useReducer, useState } from 'react';
import { useIsLogined, useUserInfo } from '../store/user';
import { useIsLogined } from '../store/user';
const useSocketStore = create<{
socket: Socket | null;

View File

@ -11,6 +11,11 @@ export default defineConfig({
clearScreen: false,
server: {
proxy: {
'/socket.io': {
target: 'ws://localhost:12345',
changeOrigin: true,
ws: true,
},
'/trpc': {
target: 'http://localhost:12345',
},

View File

@ -3,11 +3,14 @@ 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(
path.resolve(process.cwd(), './scripts/install.sh')
env.isProd
? path.resolve(process.cwd(), './scripts/install.sh')
: path.resolve(process.cwd(), '../../scripts/install.sh')
);
serverStatusRouter.post(

View File

@ -1,4 +1,5 @@
export const env = {
isProd: process.env.NODE_ENV === 'production',
port: Number(process.env.PORT || 12345),
allowRegister: checkEnvTrusty(process.env.ALLOW_REGISTER),
allowOpenapi: checkEnvTrusty(process.env.ALLOW_OPENAPI),