-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
258 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,178 @@ | ||
# App API | ||
|
||
Vinxi is designed primary as a runtime for your server applications. The routers included in the app drive the behavior of the server, but the server is in your control via the `App` API. | ||
|
||
## `App` API | ||
|
||
### `createApp(config)` | ||
|
||
The primary way to use Vinxi is to use `createApp` to create an app, | ||
|
||
::: code-group | ||
|
||
```ts [app.js] | ||
import { createApp } from "vinxi"; | ||
|
||
export default createApp({ | ||
routers: [ | ||
{ | ||
name: "public", | ||
type: "static", | ||
dir: "./public", | ||
}, | ||
{ | ||
name: "api", | ||
type: "http", | ||
handler: "./server.ts", | ||
target: "server", | ||
}, | ||
// ... other routers | ||
], | ||
}); | ||
``` | ||
|
||
::: | ||
|
||
::: info | ||
|
||
To learn more about how to describe your app to Vinxi and use `createApp`, see the [App API](/api/app). | ||
|
||
::: | ||
|
||
The `createApp` function return an instance of `App`. This instance has the following methods that you can use to create your own experience: | ||
|
||
### `app.dev()` | ||
|
||
Starts the development server for the app. | ||
|
||
```ts twoslash | ||
import { createApp } from "vinxi"; | ||
|
||
const app = createApp({ | ||
routers: [ | ||
// ... routers | ||
], | ||
}); | ||
|
||
await app.dev(); | ||
``` | ||
|
||
### `app.build()` | ||
|
||
Builds the app for production. | ||
|
||
```ts twoslash | ||
import { createApp } from "vinxi"; | ||
|
||
const app = createApp({ | ||
routers: [ | ||
// ... routers | ||
], | ||
}); | ||
|
||
await app.build(); | ||
``` | ||
|
||
### `app.getRouter(name)` | ||
|
||
Gets a router by name. | ||
|
||
```ts twoslash | ||
import { createApp } from "vinxi"; | ||
|
||
const app = createApp({ | ||
routers: [ | ||
// ... routers | ||
], | ||
}); | ||
|
||
const router = app.getRouter("api"); | ||
``` | ||
|
||
## Running a Vinxi app using `node` | ||
|
||
You can run a file that creates a Vinxi app using the regular `node` CLI. | ||
|
||
```bash | ||
node app.js | ||
``` | ||
|
||
If you run the app without any additional options, it will just create the `App` and not start the server. | ||
|
||
You can use the `--dev` option to start the development server for your application. | ||
|
||
```bash | ||
node app.js --dev | ||
``` | ||
|
||
And, you can use the `--build` option to build your application for production. | ||
|
||
```bash | ||
node app.js --build | ||
``` | ||
|
||
::: info | ||
|
||
The `--dev` and `--build` flags use the underlying [`app.dev()`](#app-dev) and [`app.build()`](#app-build) methods to start the development server and build the app. They are just shortcuts to make it easier to run the app using `node`. | ||
|
||
::: | ||
|
||
The built application can be started by running the built node server file using `node` or whatever preset you decided the build the app with. | ||
|
||
```bash | ||
node .output/server/index.mjs | ||
``` | ||
|
||
## Wrapping Vinxi | ||
|
||
You can also wrap Vinxi in your own runtime to add a pre-configured set of routers, middlewares, and other settings. You can also use it to add your own custom logic to the server. | ||
|
||
::: code-group | ||
|
||
```ts [node_modules/framework] | ||
import { createApp } from "vinxi"; | ||
|
||
export function createFrameworkApp() { | ||
return createApp({ | ||
routers: [ | ||
{ | ||
name: "public", | ||
type: "static", | ||
dir: "./public", | ||
}, | ||
{ | ||
name: "api", | ||
type: "http", | ||
handler: "./server.ts", | ||
target: "server", | ||
}, | ||
// ... other routers | ||
], | ||
}); | ||
} | ||
``` | ||
|
||
::: | ||
|
||
::: code-group | ||
|
||
```ts [app.js] | ||
import { createFrameworkApp } from "framework"; | ||
|
||
export default createFrameworkApp(); | ||
``` | ||
|
||
::: | ||
|
||
The created app can be used by your own CLI or other runtime to start the development server and build the app | ||
|
||
```ts [bin/cli.mjs] | ||
import { createFrameworkApp } from "framework"; | ||
|
||
const app = createFrameworkApp(); | ||
if (process.argv.includes("--dev")) { | ||
await app.dev(); | ||
} else if (process.argv.includes("--build")) { | ||
await app.build(); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Router API | ||
|
||
(Coming soon) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Client Router API | ||
|
||
(Coming soon) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# HTTP Router API | ||
|
||
(Coming soon) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# SPA Router API | ||
|
||
(Coming soon) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Static Router API | ||
|
||
(Coming soon) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.