feat: deployctl is not needed anymore (#45)
Deno Deploy now supports Deno.listen and Deno.serveHttp.
This commit is contained in:
Vendored
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"deno.enable": true,
|
"deno.enable": true,
|
||||||
"deno.lint": true,
|
"deno.lint": true,
|
||||||
"deno.unstable": false,
|
"deno.unstable": true,
|
||||||
"deno.config": "./tsconfig.json"
|
"deno.config": "./tsconfig.json"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,10 +43,10 @@ The `fresh` CLI can scaffold a new project for you. To scaffold a project in the
|
|||||||
fresh init myproject
|
fresh init myproject
|
||||||
```
|
```
|
||||||
|
|
||||||
To now start the project, use [`deployctl`](https://deno.land/x/deploy):
|
To now start the project, call `deno run`:
|
||||||
|
|
||||||
```
|
```
|
||||||
deployctl run --no-check --watch main.ts
|
deno run -A --unstable --config tsconfig.json --watch main.ts
|
||||||
```
|
```
|
||||||
|
|
||||||
To deploy the script to [Deno Deploy](https://deno.com/deploy), push your
|
To deploy the script to [Deno Deploy](https://deno.com/deploy), push your
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ switch (subcommand) {
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (args.version) {
|
if (args.version) {
|
||||||
console.log(`deployctl ${VERSION}`);
|
console.log(`fresh ${VERSION}`);
|
||||||
Deno.exit(0);
|
Deno.exit(0);
|
||||||
}
|
}
|
||||||
if (args.help) {
|
if (args.help) {
|
||||||
|
|||||||
@@ -4,15 +4,11 @@ Welcome to the `fresh` documentation.
|
|||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
The documentation assumes you have Deno 1.9.2 or later, and `deployctl` 0.3.0
|
The documentation assumes you have Deno 1.12.0 or later installed.
|
||||||
installed.
|
|
||||||
|
|
||||||
To install Deno, follow the installation instructions in the manual:
|
To install Deno, follow the installation instructions in the manual:
|
||||||
https://deno.land/manual/getting_started/installation
|
https://deno.land/manual/getting_started/installation
|
||||||
|
|
||||||
To install `deployctl`, follow the installation instructions here:
|
|
||||||
https://deno.land/x/deploy#install
|
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
`fresh` comes with a CLI tool, conveniently also called `fresh`. It is used to
|
`fresh` comes with a CLI tool, conveniently also called `fresh`. It is used to
|
||||||
@@ -46,10 +42,10 @@ To learn more about how projects are structured, take a look at the
|
|||||||
|
|
||||||
## Running the project locally
|
## Running the project locally
|
||||||
|
|
||||||
You can now run your new project locally with `deployctl`:
|
You can now run your new project locally using the `deno` CLI:
|
||||||
|
|
||||||
```
|
```
|
||||||
deployctl run --watch --no-check ./main.ts
|
deno run -A --unstable --config tsconfig.json --watch main.ts
|
||||||
```
|
```
|
||||||
|
|
||||||
The `--watch` option will cause your script to be reloaded on any changes to the
|
The `--watch` option will cause your script to be reloaded on any changes to the
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ important files are `main.ts`, `routes.gen.ts`, and the pages and api routes in
|
|||||||
the `pages` subfolder.
|
the `pages` subfolder.
|
||||||
|
|
||||||
The `main.ts` file is the entrypoint to your project. It is the file you link in
|
The `main.ts` file is the entrypoint to your project. It is the file you link in
|
||||||
Deno Deploy, or run locally with `deployctl`.
|
Deno Deploy, or run locally with the `deno` CLI.
|
||||||
|
|
||||||
The `routes.gen.ts` file is a manifest of all pages and api routes in a project.
|
The `routes.gen.ts` file is a manifest of all pages and api routes in a project.
|
||||||
When moving around or creating new pages, this file needs to be updated. This is
|
When moving around or creating new pages, this file needs to be updated. This is
|
||||||
|
|||||||
+1
-7
@@ -2,16 +2,10 @@
|
|||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
Install deployctl:
|
|
||||||
|
|
||||||
```
|
|
||||||
deno install --allow-read --allow-write --allow-env --allow-net --allow-run --no-check -r -f https://deno.land/x/deploy/deployctl.ts
|
|
||||||
```
|
|
||||||
|
|
||||||
Start the project:
|
Start the project:
|
||||||
|
|
||||||
```
|
```
|
||||||
deployctl run --no-check --watch main.ts
|
deno run -A --unstable --config tsconfig.json --watch main.ts
|
||||||
```
|
```
|
||||||
|
|
||||||
After adding, removing, or moving a page in the `pages` directory, run:
|
After adding, removing, or moving a page in the `pages` directory, run:
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
"lib": ["dom", "deno.ns", "deno.unstable"],
|
||||||
"jsxFactory": "h",
|
"jsxFactory": "h",
|
||||||
"jsxFragmentFactory": "Fragment"
|
"jsxFragmentFactory": "Fragment"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,4 +8,4 @@ test:
|
|||||||
deno test --no-check -A --config tsconfig.json
|
deno test --no-check -A --config tsconfig.json
|
||||||
|
|
||||||
watch_example:
|
watch_example:
|
||||||
deployctl run --watch --no-check example/main.ts
|
deno run -A --unstable --config example/tsconfig.json --watch example/main.ts
|
||||||
+2
-7
@@ -137,6 +137,7 @@ export default (_req: Request): Response => {
|
|||||||
const TSCONFIG_JSON = JSON.stringify(
|
const TSCONFIG_JSON = JSON.stringify(
|
||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
"lib": ["dom", "deno.ns", "deno.unstable"],
|
||||||
"jsxFactory": "h",
|
"jsxFactory": "h",
|
||||||
"jsxFragmentFactory": "Fragment",
|
"jsxFragmentFactory": "Fragment",
|
||||||
},
|
},
|
||||||
@@ -162,16 +163,10 @@ start(routes);
|
|||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
Install deployctl:
|
|
||||||
|
|
||||||
\`\`\`
|
|
||||||
deno install --allow-read --allow-write --allow-env --allow-net --allow-run --no-check -r -f https://deno.land/x/deploy/deployctl.ts
|
|
||||||
\`\`\`
|
|
||||||
|
|
||||||
Start the project:
|
Start the project:
|
||||||
|
|
||||||
\`\`\`
|
\`\`\`
|
||||||
deployctl run --no-check --watch main.ts
|
deno run -A --unstable --config tsconfig.json --watch main.ts
|
||||||
\`\`\`
|
\`\`\`
|
||||||
|
|
||||||
After adding, removing, or moving a page in the \`pages\` directory, run:
|
After adding, removing, or moving a page in the \`pages\` directory, run:
|
||||||
|
|||||||
@@ -2,3 +2,9 @@ export const INTERNAL_PREFIX = "/_frsh";
|
|||||||
export const BUILD_ID = Deno.env.get("DENO_DEPLOYMENT_ID") ||
|
export const BUILD_ID = Deno.env.get("DENO_DEPLOYMENT_ID") ||
|
||||||
crypto.randomUUID();
|
crypto.randomUUID();
|
||||||
export const JS_PREFIX = `/js`;
|
export const JS_PREFIX = `/js`;
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface Crypto {
|
||||||
|
randomUUID(): string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ export class ServerContext {
|
|||||||
if (path.startsWith("/api/")) {
|
if (path.startsWith("/api/")) {
|
||||||
const handlers = Object.fromEntries(
|
const handlers = Object.fromEntries(
|
||||||
Object.entries(module as ApiRouteModule).filter(([method]) =>
|
Object.entries(module as ApiRouteModule).filter(([method]) =>
|
||||||
method === "default" || router.METHODS.includes(method)
|
method === "default" ||
|
||||||
|
(router.METHODS as readonly string[]).includes(method)
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
const apiRoute: ApiRoute = {
|
const apiRoute: ApiRoute = {
|
||||||
|
|||||||
+1
-1
@@ -14,4 +14,4 @@ export { lookup as mediaTypeLookup } from "https://deno.land/x/media_types@v2.9.
|
|||||||
// @deno-types="https://unpkg.com/esbuild-wasm@0.11.19/esm/browser.d.ts"
|
// @deno-types="https://unpkg.com/esbuild-wasm@0.11.19/esm/browser.d.ts"
|
||||||
import * as esbuild from "https://gist.githubusercontent.com/lucacasonato/358c6b7e8198bfb2cf3d220e49fdcf5f/raw/3714cb0f59606eefc29ed0fea36d4cd93549938b/esbuild-wasm.js";
|
import * as esbuild from "https://gist.githubusercontent.com/lucacasonato/358c6b7e8198bfb2cf3d220e49fdcf5f/raw/3714cb0f59606eefc29ed0fea36d4cd93549938b/esbuild-wasm.js";
|
||||||
export { esbuild };
|
export { esbuild };
|
||||||
export { denoPlugin } from "https://deno.land/x/esbuild_deno_loader@0.2.0/mod.ts";
|
export { denoPlugin } from "https://deno.land/x/esbuild_deno_loader@0.3.0/mod.ts";
|
||||||
|
|||||||
+19
-3
@@ -14,7 +14,23 @@ export { router, ServerContext };
|
|||||||
export function start(routes: Routes) {
|
export function start(routes: Routes) {
|
||||||
const ctx = ServerContext.fromRoutes(routes);
|
const ctx = ServerContext.fromRoutes(routes);
|
||||||
const app = router.router(ctx.routes());
|
const app = router.router(ctx.routes());
|
||||||
addEventListener("fetch", (event: FetchEvent) => {
|
serve(app);
|
||||||
event.respondWith(app(event.request));
|
}
|
||||||
});
|
|
||||||
|
async function serve(handler: (req: Request) => Response | Promise<Response>) {
|
||||||
|
async function handleConn(conn: Deno.Conn) {
|
||||||
|
const httpConn = Deno.serveHttp(conn);
|
||||||
|
for await (const e of httpConn) {
|
||||||
|
e.respondWith(handler(e.request))
|
||||||
|
.catch((e) => console.error("Failed handing a request:", e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const listener = Deno.listen({ port: 8000 });
|
||||||
|
const addr = listener.addr as Deno.NetAddr;
|
||||||
|
console.log(`Listening on http://${addr.hostname}:${addr.port}`);
|
||||||
|
for await (const conn of listener) {
|
||||||
|
handleConn(conn)
|
||||||
|
.catch((e) => console.error("Failed serving a connection:", e));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,16 +2,10 @@
|
|||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
Install deployctl:
|
|
||||||
|
|
||||||
```
|
|
||||||
deno install --allow-read --allow-write --allow-env --allow-net --allow-run --no-check -r -f https://deno.land/x/deploy/deployctl.ts
|
|
||||||
```
|
|
||||||
|
|
||||||
Start the project:
|
Start the project:
|
||||||
|
|
||||||
```
|
```
|
||||||
deployctl run --no-check --watch main.ts
|
deno run -A --unstable --config tsconfig.json --watch main.ts
|
||||||
```
|
```
|
||||||
|
|
||||||
After adding, removing, or moving a page in the `pages` directory, run:
|
After adding, removing, or moving a page in the `pages` directory, run:
|
||||||
|
|||||||
Reference in New Issue
Block a user