0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

refactor: fix dev experience

This commit is contained in:
Gao Sun 2023-02-18 14:33:47 +08:00
parent ed4894a19f
commit 8fa9e7a4a1
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
5 changed files with 22 additions and 6 deletions

View file

@ -10,7 +10,7 @@
"dev": "pnpm -r prepack && pnpm start:dev",
"dev:cloud": "pnpm -r prepack && pnpm start:dev:cloud",
"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 .",
"cli": "logto",
"alteration": "logto db alt",

View file

@ -15,12 +15,15 @@
"build": "rm -rf build/ && tsc -p tsconfig.build.json",
"lint": "eslint --ext .ts src",
"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": {
"@logto/shared": "workspace:*",
"@silverhand/essentials": "2.2.0",
"@withtyped/postgres": "^0.6.0",
"@withtyped/server": "^0.6.0",
"chalk": "^5.0.0",
"http-proxy": "^1.18.1",
"mime-types": "^2.1.35"
},

View file

@ -1,4 +1,5 @@
import type { HttpContext, NextFunction, RequestContext } from '@withtyped/server';
import chalk from 'chalk';
import type { ServerOptions } from 'http-proxy';
import HttpProxy from 'http-proxy';
@ -12,6 +13,13 @@ export default function withHttpProxy<InputContext extends RequestContext>(
) {
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 (
context: InputContext,
next: NextFunction<InputContext>,
@ -28,10 +36,8 @@ export default function withHttpProxy<InputContext extends RequestContext>(
}
await new Promise<void>((resolve) => {
response.once('finish', resolve);
proxy.web(request, response, options);
proxy.on('proxyRes', (_, __, response) => {
response.on('end', resolve);
});
});
return next({ ...context, status: 'ignore' });

View file

@ -1,4 +1,7 @@
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;

View file

@ -106,6 +106,7 @@ importers:
packages/cloud:
specifiers:
'@logto/shared': workspace:*
'@silverhand/eslint-config': 2.0.1
'@silverhand/essentials': 2.2.0
'@silverhand/ts-config': 2.0.2
@ -114,6 +115,7 @@ importers:
'@types/node': ^18.11.18
'@withtyped/postgres': ^0.6.0
'@withtyped/server': ^0.6.0
chalk: ^5.0.0
eslint: ^8.21.0
http-proxy: ^1.18.1
lint-staged: ^13.0.0
@ -122,9 +124,11 @@ importers:
prettier: ^2.8.1
typescript: ^4.9.4
dependencies:
'@logto/shared': link:../shared
'@silverhand/essentials': 2.2.0
'@withtyped/postgres': 0.6.0_@withtyped+server@0.6.0
'@withtyped/server': 0.6.0
chalk: 5.1.2
http-proxy: 1.18.1
mime-types: 2.1.35
devDependencies: