Commit eb740c53 authored by Joe Haddad's avatar Joe Haddad Committed by Luis Fernando Alvarez D

Remove public/ file example (#8056)

parent 7eed8380
# Public file serving example
## How to use
### Using `create-next-app`
Execute [`create-next-app`](https://github.com/segmentio/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example:
```bash
npx create-next-app --example public-file-serving public-file-serving-app
# or
yarn create next-app --example public-file-serving public-file-serving-app
```
### Download manually
Download the example:
```bash
curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/public-file-serving
cd public-file-serving
```
Install it and run:
```bash
npm install
npm run dev
# or
yarn
yarn dev
```
### Serverless
Simply adjust your `now.json` (similar to in this example) by using the [routes configuration](https://zeit.co/docs/v2/deployments/configuration/#routes).
Afterwards, deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))
```bash
now
```
## The idea behind the example
This example demonstrates how to serve files such as `/robots.txt` and `/sitemap.xml` from the root using the `public` folder in both a serverless and non-serverless environment.
module.exports = {
target: 'serverless'
}
{
"version": 2,
"alias": "https://serverless-static-files.now.sh",
"builds": [{ "src": "next.config.js", "use": "@now/next" }],
"routes": [
{
"src": "/_next/static/(?:[^/]+/pages|chunks|runtime)/.+",
"headers": { "cache-control": "immutable" }
},
{
"src": "^/(favicon.ico|manifest.json|humans.txt|sitemap.xml|sitemap.xsl)$",
"headers": { "cache-control": "max-age=300 must-revalidate" }
}
]
}
{
"name": "public-file-serving",
"version": "1.0.0",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "latest",
"react": "^16.7.0",
"react-dom": "^16.7.0"
}
}
export default () => (
<ul>
<li>
<a href='/robots.txt'>/robots.txt</a>
</li>
<li>
<a href='/sitemap.xml'>/sitemap.xml</a>
</li>
<li>
<a href='/favicon.ico'>/favicon.ico</a>
</li>
</ul>
)
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://www.example.com/foo.html</loc>
</url>
</urlset>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment