mirror of
https://github.com/logto-io/logto.git
synced 2025-03-10 22:22:45 -05:00
refactor: fix dev experience
This commit is contained in:
parent
ed4894a19f
commit
8fa9e7a4a1
5 changed files with 22 additions and 6 deletions
|
@ -10,7 +10,7 @@
|
||||||
"dev": "pnpm -r prepack && pnpm start:dev",
|
"dev": "pnpm -r prepack && pnpm start:dev",
|
||||||
"dev:cloud": "pnpm -r prepack && pnpm start:dev:cloud",
|
"dev:cloud": "pnpm -r prepack && pnpm start:dev:cloud",
|
||||||
"start:dev": "pnpm -r --parallel --filter=!@logto/integration-tests --filter=!@logto/cloud dev",
|
"start:dev": "pnpm -r --parallel --filter=!@logto/integration-tests --filter=!@logto/cloud dev",
|
||||||
"start:dev:cloud": "ADMIN_TENANT_ENDPOINT=http://localhost:3002 pnpm -r --parallel --filter=!@logto/integration-tests dev",
|
"start:dev:cloud": "pnpm -r --parallel --filter=!@logto/integration-tests dev",
|
||||||
"start": "cd packages/core && NODE_ENV=production node .",
|
"start": "cd packages/core && NODE_ENV=production node .",
|
||||||
"cli": "logto",
|
"cli": "logto",
|
||||||
"alteration": "logto db alt",
|
"alteration": "logto db alt",
|
||||||
|
|
|
@ -15,12 +15,15 @@
|
||||||
"build": "rm -rf build/ && tsc -p tsconfig.build.json",
|
"build": "rm -rf build/ && tsc -p tsconfig.build.json",
|
||||||
"lint": "eslint --ext .ts src",
|
"lint": "eslint --ext .ts src",
|
||||||
"lint:report": "pnpm lint --format json --output-file report.json",
|
"lint:report": "pnpm lint --format json --output-file report.json",
|
||||||
"dev": "rm -rf build/ && nodemon"
|
"dev": "rm -rf build/ && nodemon",
|
||||||
|
"start": "NODE_ENV=production node build/index.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@logto/shared": "workspace:*",
|
||||||
"@silverhand/essentials": "2.2.0",
|
"@silverhand/essentials": "2.2.0",
|
||||||
"@withtyped/postgres": "^0.6.0",
|
"@withtyped/postgres": "^0.6.0",
|
||||||
"@withtyped/server": "^0.6.0",
|
"@withtyped/server": "^0.6.0",
|
||||||
|
"chalk": "^5.0.0",
|
||||||
"http-proxy": "^1.18.1",
|
"http-proxy": "^1.18.1",
|
||||||
"mime-types": "^2.1.35"
|
"mime-types": "^2.1.35"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import type { HttpContext, NextFunction, RequestContext } from '@withtyped/server';
|
import type { HttpContext, NextFunction, RequestContext } from '@withtyped/server';
|
||||||
|
import chalk from 'chalk';
|
||||||
import type { ServerOptions } from 'http-proxy';
|
import type { ServerOptions } from 'http-proxy';
|
||||||
import HttpProxy from 'http-proxy';
|
import HttpProxy from 'http-proxy';
|
||||||
|
|
||||||
|
@ -12,6 +13,13 @@ export default function withHttpProxy<InputContext extends RequestContext>(
|
||||||
) {
|
) {
|
||||||
const proxy = createProxy(options);
|
const proxy = createProxy(options);
|
||||||
|
|
||||||
|
proxy.on('start', (request, __, target) => {
|
||||||
|
console.log(
|
||||||
|
`\t${chalk.italic(chalk.gray('proxy ->'))}`,
|
||||||
|
new URL(request.url ?? '/', typeof target === 'object' ? target.href : target).toString()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
return async (
|
return async (
|
||||||
context: InputContext,
|
context: InputContext,
|
||||||
next: NextFunction<InputContext>,
|
next: NextFunction<InputContext>,
|
||||||
|
@ -28,10 +36,8 @@ export default function withHttpProxy<InputContext extends RequestContext>(
|
||||||
}
|
}
|
||||||
|
|
||||||
await new Promise<void>((resolve) => {
|
await new Promise<void>((resolve) => {
|
||||||
|
response.once('finish', resolve);
|
||||||
proxy.web(request, response, options);
|
proxy.web(request, response, options);
|
||||||
proxy.on('proxyRes', (_, __, response) => {
|
|
||||||
response.on('end', resolve);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return next({ ...context, status: 'ignore' });
|
return next({ ...context, status: 'ignore' });
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
import { defaultTenantId } from '@logto/schemas';
|
import { defaultTenantId } from '@logto/schemas';
|
||||||
|
|
||||||
export const adminTenantEndpoint = process.env.ADMIN_TENANT_ENDPOINT ?? window.location.origin;
|
const isProduction = process.env.NODE_ENV === 'production';
|
||||||
|
export const adminTenantEndpoint =
|
||||||
|
process.env.ADMIN_TENANT_ENDPOINT ??
|
||||||
|
(isProduction ? window.location.origin : 'http://localhost:3002');
|
||||||
export const userTenantId = process.env.USER_TENANT_ID ?? defaultTenantId;
|
export const userTenantId = process.env.USER_TENANT_ID ?? defaultTenantId;
|
||||||
|
|
4
pnpm-lock.yaml
generated
4
pnpm-lock.yaml
generated
|
@ -106,6 +106,7 @@ importers:
|
||||||
|
|
||||||
packages/cloud:
|
packages/cloud:
|
||||||
specifiers:
|
specifiers:
|
||||||
|
'@logto/shared': workspace:*
|
||||||
'@silverhand/eslint-config': 2.0.1
|
'@silverhand/eslint-config': 2.0.1
|
||||||
'@silverhand/essentials': 2.2.0
|
'@silverhand/essentials': 2.2.0
|
||||||
'@silverhand/ts-config': 2.0.2
|
'@silverhand/ts-config': 2.0.2
|
||||||
|
@ -114,6 +115,7 @@ importers:
|
||||||
'@types/node': ^18.11.18
|
'@types/node': ^18.11.18
|
||||||
'@withtyped/postgres': ^0.6.0
|
'@withtyped/postgres': ^0.6.0
|
||||||
'@withtyped/server': ^0.6.0
|
'@withtyped/server': ^0.6.0
|
||||||
|
chalk: ^5.0.0
|
||||||
eslint: ^8.21.0
|
eslint: ^8.21.0
|
||||||
http-proxy: ^1.18.1
|
http-proxy: ^1.18.1
|
||||||
lint-staged: ^13.0.0
|
lint-staged: ^13.0.0
|
||||||
|
@ -122,9 +124,11 @@ importers:
|
||||||
prettier: ^2.8.1
|
prettier: ^2.8.1
|
||||||
typescript: ^4.9.4
|
typescript: ^4.9.4
|
||||||
dependencies:
|
dependencies:
|
||||||
|
'@logto/shared': link:../shared
|
||||||
'@silverhand/essentials': 2.2.0
|
'@silverhand/essentials': 2.2.0
|
||||||
'@withtyped/postgres': 0.6.0_@withtyped+server@0.6.0
|
'@withtyped/postgres': 0.6.0_@withtyped+server@0.6.0
|
||||||
'@withtyped/server': 0.6.0
|
'@withtyped/server': 0.6.0
|
||||||
|
chalk: 5.1.2
|
||||||
http-proxy: 1.18.1
|
http-proxy: 1.18.1
|
||||||
mime-types: 2.1.35
|
mime-types: 2.1.35
|
||||||
devDependencies:
|
devDependencies:
|
||||||
|
|
Loading…
Add table
Reference in a new issue