Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapter plugin toml file #5

Merged
merged 3 commits into from
Aug 5, 2023
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ TODO
- proxy netlify cli dev option?
- should use _src/_ or _public/_? depends on dev vs production mode? Interestingly, the manual way only worked deployed when using _public/_
- if esbuild worked w/ `import.meta.url`, we could probably ship unzipped bundles, and then dev would also work?
1. [ ] Need to provide custom _netlify.toml_?
1. [ ] Make sure to spread all headers / response properties in netlify functions adapter output
1. [x] Need to provide custom _netlify.toml_?
1. [x] Make sure to spread all headers / response properties in netlify functions adapter output
1. [ ] SSR pages are bundling into _public/api/_ directory ?
1. [ ] Keep it as an experimental feature for 1.0 (or per platform?)
15 changes: 15 additions & 0 deletions adapter-netlify.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ async function netlifyAdapter(compilation) {
const adapterOutputUrl = new URL('./netlify/functions/', scratchDir);
const ssrPages = compilation.graph.filter(page => page.isSSR);
const apiRoutes = compilation.manifest.apis;
let redirects = '';

if (!await checkResourceExists(adapterOutputUrl)) {
await fs.mkdir(adapterOutputUrl, { recursive: true });
}

const files = await fs.readdir(outputDir);
const isExecuteRouteModule = files.find(file => file.startsWith('execute-route-module'));

await fs.mkdir(new URL('./netlify/functions/', projectDirectory), { recursive: true });

for (const page of ssrPages) {
Expand Down Expand Up @@ -110,6 +112,13 @@ async function netlifyAdapter(compilation) {
}

await createOutputZip(id, outputType, new URL(`./${id}/`, adapterOutputUrl), projectDirectory);

redirects +=`/${id}/ /.netlify/functions/${id}
`
}

if (apiRoutes.size > 0) {
redirects += `/api/* /.netlify/functions/api-:splat`
}

for (const [key] of apiRoutes) {
Expand Down Expand Up @@ -139,6 +148,12 @@ async function netlifyAdapter(compilation) {
// https://github.com/netlify/netlify-lambda/issues/90#issuecomment-486047201
await createOutputZip(id, outputType, outputRoot, projectDirectory);
}

// https://docs.netlify.com/routing/redirects/
console.log({ redirects });
if (redirects !== '') {
await fs.writeFile(new URL('./_redirects', outputDir), redirects);
}
}

const greenwoodPluginAdapterNetlify = (options = {}) => [{
Expand Down
19 changes: 1 addition & 18 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,4 @@
skip_processing = true

[build.environment]
NODE_VERSION = "18.12.1"

# https://answers.netlify.com/t/lambda-function-es-module-support/30673/16
# [functions]
# node_bundler = "esbuild"

# https://github.com/netlify/netlify-lambda/issues/90#issuecomment-486047201
[[redirects]]
from = "/api/*"
to = "/.netlify/functions/api-:splat"
status = 200

# https://answers.netlify.com/t/serve-a-serverless-function-from-root/47275/2
[[redirects]]
from = "/artists/"
to = "/.netlify/functions/artists"
status = 200
force = true
NODE_VERSION = "18.x"