Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions starters/servers/netlify/.node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16
36 changes: 36 additions & 0 deletions starters/servers/netlify/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## Netlify

This starter site is configured to deploy to [Netlify Edge Functions](https://www.netlify.com/products/edge/), which means it will be rendered at an edge location near to your users.

### Local development

The [Netlify CLI](https://docs.netlify.com/cli/get-started/) can be used to preview a production build locally. To do so: First build your site, then to start a local server, run:

1. Build your site with `netlify build`.
2. Start a local server with `npm run serve`.
In this project, `npm run serve` uses the `netlify dev` command to spin up a server that can handle Netlify's Edge Functions locally.
3. Visit [http://localhost:8888/](http://localhost:8888/) to check out your site.

### Deployments

You can [deploy your site to Netlify](https://docs.netlify.com/site-deploys/create-deploys/) either via a Git provider integration or through the Netlify CLI. This starter site includes a `netlify.toml` file to configure your build for deployment.

#### Deploying via Git

Once your site has been pushed to your Git provider, you can either link it [in the Netlify UI](https://app.netlify.com/start) or use the CLI. To link your site to a Git provider from the Netlify CLI, run the command:

```shell
netlify link
```

This sets up [continuous deployment](https://docs.netlify.com/site-deploys/create-deploys/#deploy-with-git) for your site's repo. Whenever you push new commits to your repo, Netlify starts the build process..

#### Deploying manually via the CLI

If you wish to deploy from the CLI rather than using Git, you can use the command:

```shell
netlify deploy --build
```

You must use the `--build` flag whenever you deploy. This ensures that the Edge Functions that this starter site relies on are generated and available when you deploy your site.
3 changes: 3 additions & 0 deletions starters/servers/netlify/netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build]
publish = "dist"
command = "npm run build"
13 changes: 13 additions & 0 deletions starters/servers/netlify/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"description": "Netlify Edge Functions.",
"scripts": {
"serve": "netlify dev",
"build.ssr": "vite build --ssr src/entry.netlify.ts"
},
"devDependencies": {
"@netlify/vite-plugin-netlify-edge": "^1.1.0"
},
"qwik": {
"priority": -1
}
}
2 changes: 2 additions & 0 deletions starters/servers/netlify/public/_headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build/*
Cache-Control: public, max-age=31536000, s-maxage=31536000, immutable
27 changes: 27 additions & 0 deletions starters/servers/netlify/src/entry.netlify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { render } from './entry.ssr';

const handler = async (request: Request) => {
try {
// Handle static files
if (/\.\w+$/.test(request.url)) {
return;
}

const ssrResult = await render({
url: request.url,
base: '/build/',
});

const response = new Response(ssrResult.html, {
headers: {
'Content-Type': 'text/html; charset=utf-8',
},
});
return response;
} catch (e) {
// 500 Error
return new Response(String(e), { status: 500 });
}
};

export default handler;
17 changes: 17 additions & 0 deletions starters/servers/netlify/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "ES2017",
"module": "ES2020",
"lib": ["es2020", "DOM"],
"jsx": "react-jsx",
"jsxImportSource": "@builder.io/qwik",
"strict": true,
"resolveJsonModule": true,
"moduleResolution": "node",
"esModuleInterop": true,
"skipLibCheck": true,
"incremental": true,
"types": ["vite/client"]
},
"include": ["src"]
}
16 changes: 16 additions & 0 deletions starters/servers/netlify/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineConfig } from 'vite';
import netlifyEdge from '@netlify/vite-plugin-netlify-edge';
import { qwikVite } from '@builder.io/qwik/optimizer';

export default defineConfig(() => {
return {
plugins: [
qwikVite({
ssr: { outDir: '.netlify/edge-functions/entry.netlify' },
}),
netlifyEdge({
functionName: 'entry.netlify',
}),
],
};
});