feat(server): make startup message easier to see (#1273)
This commit is contained in:
@@ -11,7 +11,8 @@ automatically read from `.env`.
|
|||||||
```
|
```
|
||||||
$ deno task start
|
$ deno task start
|
||||||
Watcher Process started.
|
Watcher Process started.
|
||||||
Listening on http://localhost:8000
|
🍋 Fresh ready
|
||||||
|
Local: http://localhost:8000
|
||||||
```
|
```
|
||||||
|
|
||||||
If you want to start manually without Deno task, `deno run` the `main.ts` with
|
If you want to start manually without Deno task, `deno run` the `main.ts` with
|
||||||
@@ -52,7 +53,8 @@ Combining all of this we get the following `deno run` command:
|
|||||||
```
|
```
|
||||||
$ deno run --allow-net --allow-read --allow-env --allow-run --watch=static/,routes/ main.ts
|
$ deno run --allow-net --allow-read --allow-env --allow-run --watch=static/,routes/ main.ts
|
||||||
Watcher Process started.
|
Watcher Process started.
|
||||||
Listening on http://localhost:8000
|
🍋 Fresh ready
|
||||||
|
Local: http://localhost:8000
|
||||||
```
|
```
|
||||||
|
|
||||||
If you now visit http://localhost:8000, you can see the running project. Try
|
If you now visit http://localhost:8000, you can see the running project. Try
|
||||||
|
|||||||
+16
-1
@@ -1,4 +1,5 @@
|
|||||||
import { ServerContext } from "./context.ts";
|
import { ServerContext } from "./context.ts";
|
||||||
|
import * as colors from "https://deno.land/std@0.190.0/fmt/colors.ts";
|
||||||
import { serve } from "./deps.ts";
|
import { serve } from "./deps.ts";
|
||||||
export { Status } from "./deps.ts";
|
export { Status } from "./deps.ts";
|
||||||
import {
|
import {
|
||||||
@@ -71,9 +72,23 @@ export async function createHandler(
|
|||||||
export async function start(routes: Manifest, opts: StartOptions = {}) {
|
export async function start(routes: Manifest, opts: StartOptions = {}) {
|
||||||
const ctx = await ServerContext.fromManifest(routes, opts);
|
const ctx = await ServerContext.fromManifest(routes, opts);
|
||||||
opts.port ??= parseInt(Deno.env.get("PORT") || "8000");
|
opts.port ??= parseInt(Deno.env.get("PORT") || "8000");
|
||||||
|
|
||||||
|
if (!opts.onListen) {
|
||||||
|
opts.onListen = (params) => {
|
||||||
|
console.log(
|
||||||
|
`\n%c 🍋 Fresh ready %c`,
|
||||||
|
"background-color: #86efac; color: black; font-weight: bold",
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
const address = colors.cyan(`http://localhost:${params.port}/`);
|
||||||
|
const localLabel = colors.bold("Local:");
|
||||||
|
console.log(` ${localLabel} ${address}\n`);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (opts.experimentalDenoServe === true) {
|
if (opts.experimentalDenoServe === true) {
|
||||||
// @ts-ignore as `Deno.serve` is still unstable.
|
// @ts-ignore as `Deno.serve` is still unstable.
|
||||||
await Deno.serve(ctx.handler() as Deno.ServeHandler, opts);
|
await Deno.serve({ ...opts, handler: ctx.handler() });
|
||||||
} else {
|
} else {
|
||||||
await serve(ctx.handler(), opts);
|
await serve(ctx.handler(), opts);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -17,7 +17,7 @@ export async function startFreshServer(options: Deno.CommandOptions) {
|
|||||||
|
|
||||||
let started = false;
|
let started = false;
|
||||||
for await (const line of lines) {
|
for await (const line of lines) {
|
||||||
if (line.includes("Listening on http://")) {
|
if (line.includes("Fresh ready")) {
|
||||||
started = true;
|
started = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user