feat(medusa): Display admin url on start (#9643)
**What** Display the admin url on server start in the console <img width="452" alt="Screenshot 2024-10-17 at 16 07 10" src="https://github.com/user-attachments/assets/bc618371-2022-40fe-a573-4dff13f8a2ff">
This commit is contained in:
@@ -8,15 +8,16 @@ import { scheduleJob } from "node-schedule"
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
dynamicImport,
|
dynamicImport,
|
||||||
isPresent,
|
|
||||||
FileSystem,
|
FileSystem,
|
||||||
gqlSchemaToTypes,
|
gqlSchemaToTypes,
|
||||||
GracefulShutdownServer,
|
GracefulShutdownServer,
|
||||||
|
isPresent,
|
||||||
} from "@medusajs/framework/utils"
|
} from "@medusajs/framework/utils"
|
||||||
import { logger } from "@medusajs/framework/logger"
|
import { logger } from "@medusajs/framework/logger"
|
||||||
|
|
||||||
import loaders from "../loaders"
|
import loaders from "../loaders"
|
||||||
import { MedusaModule } from "@medusajs/framework/modules-sdk"
|
import { MedusaModule } from "@medusajs/framework/modules-sdk"
|
||||||
|
import { MedusaContainer } from "@medusajs/framework/types"
|
||||||
|
|
||||||
const EVERY_SIXTH_HOUR = "0 */6 * * *"
|
const EVERY_SIXTH_HOUR = "0 */6 * * *"
|
||||||
const CRON_SCHEDULE = EVERY_SIXTH_HOUR
|
const CRON_SCHEDULE = EVERY_SIXTH_HOUR
|
||||||
@@ -57,13 +58,41 @@ export async function registerInstrumentation(directory: string) {
|
|||||||
// eslint-disable-next-line no-var
|
// eslint-disable-next-line no-var
|
||||||
export var traceRequestHandler: (...args: any[]) => Promise<any> = void 0 as any
|
export var traceRequestHandler: (...args: any[]) => Promise<any> = void 0 as any
|
||||||
|
|
||||||
|
function displayAdminUrl({
|
||||||
|
container,
|
||||||
|
port,
|
||||||
|
}: {
|
||||||
|
port: string | number
|
||||||
|
container: MedusaContainer
|
||||||
|
}) {
|
||||||
|
const isProduction = ["production", "prod"].includes(
|
||||||
|
process.env.NODE_ENV || ""
|
||||||
|
)
|
||||||
|
|
||||||
|
if (isProduction) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const logger = container.resolve("logger")
|
||||||
|
const {
|
||||||
|
admin: { path: adminPath, disable },
|
||||||
|
} = container.resolve("configModule")
|
||||||
|
|
||||||
|
if (disable) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info(`Admin URL → http://localhost:${port}${adminPath}`)
|
||||||
|
}
|
||||||
|
|
||||||
async function start(args: {
|
async function start(args: {
|
||||||
directory: string
|
directory: string
|
||||||
port?: number
|
port?: number
|
||||||
types?: boolean
|
types?: boolean
|
||||||
cluster?: number
|
cluster?: number
|
||||||
}) {
|
}) {
|
||||||
const { port, directory, types } = args
|
const { port = 9000, directory, types } = args
|
||||||
|
|
||||||
async function internalStart(generateTypes: boolean) {
|
async function internalStart(generateTypes: boolean) {
|
||||||
track("CLI_START")
|
track("CLI_START")
|
||||||
await registerInstrumentation(directory)
|
await registerInstrumentation(directory)
|
||||||
@@ -88,7 +117,7 @@ async function start(args: {
|
|||||||
})
|
})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { shutdown, gqlSchema } = await loaders({
|
const { shutdown, gqlSchema, container } = await loaders({
|
||||||
directory,
|
directory,
|
||||||
expressApp: app,
|
expressApp: app,
|
||||||
})
|
})
|
||||||
@@ -109,6 +138,7 @@ async function start(args: {
|
|||||||
const server = GracefulShutdownServer.create(
|
const server = GracefulShutdownServer.create(
|
||||||
http_.listen(port).on("listening", () => {
|
http_.listen(port).on("listening", () => {
|
||||||
logger.success(serverActivity, `Server is ready on port: ${port}`)
|
logger.success(serverActivity, `Server is ready on port: ${port}`)
|
||||||
|
displayAdminUrl({ container, port })
|
||||||
track("CLI_START_COMPLETED")
|
track("CLI_START_COMPLETED")
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user