Skip to content
This repository was archived by the owner on Sep 12, 2019. It is now read-only.

Commit 8a990e5

Browse files
authored
Merge pull request #33 from netlify/adding-readme-structure
Adding readme structure
2 parents 26ecd50 + ff18da1 commit 8a990e5

File tree

2 files changed

+317
-87
lines changed

2 files changed

+317
-87
lines changed

README.md

Lines changed: 102 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,114 @@ netlify plugins:link .
2929

3030
Now you're both ready to start testing netlify dev and to contribute to the project.
3131

32-
## Functionality Notes
32+
### Netlify Dev usage
33+
34+
```bash
35+
USAGE
36+
$ netlify dev
37+
38+
OPTIONS
39+
-c, --cmd=cmd command to run
40+
-d, --devport=devport port of the dev server started by command
41+
-d, --dir=dir dir with static files
42+
-f, --functions=functions Specify a functions folder to serve
43+
-o, --offline disables any features that require network access
44+
-p, --port=port port of netlify dev
45+
46+
DESCRIPTION
47+
The dev command will run a local dev server with Netlify's proxy and redirect rules
48+
49+
EXAMPLES
50+
$ netlify dev
51+
$ netlify dev -c "yarn start"
52+
$ netlify dev -c hugo
53+
54+
COMMANDS
55+
dev:exec Exec command
56+
```
57+
58+
### Redirects
59+
60+
Netlify Dev has the ability emulate the [redirect capability](https://www.netlify.com/docs/redirects/) Netlify provide on the [ADN](https://netlify.com/features/adn) in your local environment. The same redirect rules which you configure to run on the edge, will also work in your local builds.
61+
62+
Netlify dev supports redirect rules defined in either `_redirects` or `netlify.toml` files.
63+
64+
The order of precedence for applying redirect rules is:
65+
66+
1. `_redirects` file (in the project's publish folder)
67+
1. `netlify.toml` file (in the project's publish folder)
68+
1. `netlify.toml` file (in the project's root folder)
69+
70+
See the [Redirects Documentation](https://www.netlify.com/docs/redirects/) for more information on Netlify's redirect and proxying capabilities.
71+
72+
73+
#### Running the project and accessing redirects
74+
```bash
75+
# Build, serve and hot-reload changes
76+
$ netlify dev
77+
```
78+
79+
80+
### Project detection
81+
82+
Netlify Dev will attempt to detect the SSG or build command that you are using, and run these on your behalf, while adding other development utilities.
83+
84+
The number of project types which Netlify Dev can detect is growing, but if yours is not yet supported automatically, you can instruct Netlify Dev to run the project on your behalf by declaring it in a `[dev]` block of your `netlify.toml` file.
85+
86+
```toml
3387
34-
- `netlify dev` now supports both `_redirects` and `netlify.toml` for redirects and has the same logic around loading order as our system (\_redirects, toml in public folder, toml in base)
35-
- `netlify dev` can be configured for projects we don’t detect out of the box with a `[dev]` block in the toml file
88+
#sample dev block in the toml
89+
[dev]
90+
#TODO: what does this look like?
3691
37-
## `netlify functions:create`
92+
```
93+
94+
95+
### Netlify Functions
96+
97+
Netlify can also create serverless functions for you locally as part of Netlify Functions. The serverless functions can then be run by Netlify Dev in the same way that wold be when deployed to the cloud.
3898
39-
Create a new function from a given template.
99+
A number of function templates are available to get you started, and you can add your own utility functions to suit your own project development needs.
40100
41-
Examples:
101+
Create a new function
42102
103+
```bash
104+
$ netlify functions:create
43105
```
44-
netlify functions:create
45-
netlify functions:create hello-world
46-
netlify functions:create --name hello-world
47-
netlify functions:create hello-world --dir
48-
netlify functions:create hello-world --url https://github.com/netlify-labs/all-the-functions/tree/master/functions/9-using-middleware
106+
107+
More detailed usage examples:
108+
109+
```bash
110+
# Create a new function from one of the
111+
# available templates offered when prompted
112+
$ netlify functions:create
113+
114+
# Create a new function with a given name
115+
$ netlify functions:create hello-world
116+
# or
117+
$ netlify functions:create --name hello-world
118+
119+
# Create a new function in a subdirectory
120+
# rather than as a single file
121+
$ netlify functions:create hello-world --dir
122+
123+
# Create a new function by cloning a template from a remote url
124+
# organised with dependencies installed into a subdirectory
125+
$ netlify functions:create hello-world --url https://github.com/netlify-labs/all-the-functions/tree/master/functions/9-using-middleware
49126
```
50127
51-
You can just call `netlify functions:create` and the prompts will guide you all the way, however you can also supply a first argument to name the function. By default it creates a single file, however you can also use a `--dir` flag to create a function as a directory.
128+
#### Executing Netlify Functions
129+
130+
After creating serverless functions, Netlify Dev can serve thes to you as part of your local build. This emulates the behaviour of Netlify Functions when deployed to Netlify.
131+
132+
```bash
133+
# Build, serve and hot-reload changes
134+
$ netlify dev
135+
```
136+
137+
Each serverless function will be exposed on a URL corresponding to its path and file name.
138+
139+
140+
`./functions/hello-world.js` -> `http://localhost:{PORT}/.netlify/functions/hello-world`
52141
53-
By passing a URL to a folder in a github repo to the `--url` flag, you can clone new templates. Dependencies are installed inside its own folder. Example: `netlify functions:create hello-world --url https://github.com/netlify-labs/all-the-functions/tree/master/functions/9-using-middleware`
142+
`./functions/my-api/hello-world.js` -> `http://localhost:{PORT}/.netlify/functions/my-api/hello-world`

0 commit comments

Comments
 (0)