mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Setup eleventy serverless
This commit is contained in:
parent
6b2a827a11
commit
f839b829f4
5 changed files with 109 additions and 81 deletions
|
|
@ -33,6 +33,8 @@ import { transformSync } from 'esbuild'
|
||||||
|
|
||||||
import nuxtConfig from './nuxt.config'
|
import nuxtConfig from './nuxt.config'
|
||||||
|
|
||||||
|
const { EleventyServerlessBundlerPlugin } = require("@11ty/eleventy");
|
||||||
|
|
||||||
// Setup dotenv
|
// Setup dotenv
|
||||||
dotenv.config()
|
dotenv.config()
|
||||||
|
|
||||||
|
|
@ -173,6 +175,11 @@ module.exports = function ( eleventyConfig ) {
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
eleventyConfig.addPlugin(EleventyServerlessBundlerPlugin, {
|
||||||
|
name: "eleventy-builder", // The serverless function name from your permalink object
|
||||||
|
functionsDir: "./netlify/functions/",
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// https://www.11ty.dev/docs/config/#template-formats
|
// https://www.11ty.dev/docs/config/#template-formats
|
||||||
|
|
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -88,3 +88,5 @@ dist
|
||||||
/commits-data.json
|
/commits-data.json
|
||||||
.DS_Store
|
.DS_Store
|
||||||
/static/tailwind.css
|
/static/tailwind.css
|
||||||
|
netlify/functions/eleventy-builder/**
|
||||||
|
!netlify/functions/eleventy-builder/index.js
|
||||||
|
|
|
||||||
107
netlify.toml
107
netlify.toml
|
|
@ -1,71 +1,56 @@
|
||||||
[build]
|
[build]
|
||||||
publish = "dist/"
|
publish = "dist/"
|
||||||
command = "npm run generate --quiet"
|
command = "npm run generate --quiet"
|
||||||
functions = "netlify/functions/"
|
functions = "netlify/functions/"
|
||||||
|
|
||||||
|
[build.environment]
|
||||||
|
NPM_FLAGS = "--no-optional"
|
||||||
|
CI = "1"
|
||||||
|
|
||||||
|
[[redirects]]
|
||||||
[build.environment]
|
from = "/app/:slug"
|
||||||
NPM_FLAGS = "--no-optional"
|
to = "/.netlify/functions/eleventy-builder"
|
||||||
CI = "1"
|
status = 200
|
||||||
|
force = true
|
||||||
|
_generated_by_eleventy_serverless = "serverless"
|
||||||
# https://docs.netlify.com/configure-builds/file-based-configuration/#redirects
|
|
||||||
|
|
||||||
|
|
||||||
[[redirects]]
|
[[redirects]]
|
||||||
from = "/app/*"
|
from = "/app/node"
|
||||||
to = "/.netlify/functions/eleventy-builder"
|
to = "/app/nodejs"
|
||||||
status = 200
|
status = 301
|
||||||
force = true
|
|
||||||
|
|
||||||
# old node redirect
|
|
||||||
[[redirects]]
|
|
||||||
from = "/app/node"
|
|
||||||
to = "/app/nodejs"
|
|
||||||
status = 301
|
|
||||||
|
|
||||||
# old git redirect
|
|
||||||
[[redirects]]
|
|
||||||
from = "/app/git"
|
|
||||||
to = "/app/git-version-control"
|
|
||||||
status = 301
|
|
||||||
|
|
||||||
# old electron redirect
|
|
||||||
[[redirects]]
|
|
||||||
from = "/app/electron"
|
|
||||||
to = "/app/electron-framework"
|
|
||||||
status = 301
|
|
||||||
|
|
||||||
|
|
||||||
# imac redirect
|
|
||||||
[[redirects]]
|
|
||||||
from = "/device/apple-silicon-imac"
|
|
||||||
to = "/device/m1-imac/"
|
|
||||||
status = 307
|
|
||||||
|
|
||||||
|
|
||||||
# Category Redirects
|
|
||||||
[[redirects]]
|
|
||||||
from = "/kind/entertainment"
|
|
||||||
to = "/kind/entertainment-and-media-apps/"
|
|
||||||
status = 301
|
|
||||||
|
|
||||||
[[redirects]]
|
[[redirects]]
|
||||||
from = "/kind/photo-tools"
|
from = "/app/git"
|
||||||
to = "/kind/photo-and-graphic-tools/"
|
to = "/app/git-version-control"
|
||||||
status = 301
|
status = 301
|
||||||
|
|
||||||
|
|
||||||
# Other Redirects
|
|
||||||
|
|
||||||
# Random broken link from Chinese sites
|
|
||||||
[[redirects]]
|
|
||||||
from = "/。"
|
|
||||||
to = "/"
|
|
||||||
status = 301
|
|
||||||
|
|
||||||
[[redirects]]
|
[[redirects]]
|
||||||
from = "/%E3%80%82"
|
from = "/app/electron"
|
||||||
to = "/"
|
to = "/app/electron-framework"
|
||||||
status = 301
|
status = 301
|
||||||
|
|
||||||
|
[[redirects]]
|
||||||
|
from = "/device/apple-silicon-imac"
|
||||||
|
to = "/device/m1-imac/"
|
||||||
|
status = 307
|
||||||
|
|
||||||
|
[[redirects]]
|
||||||
|
from = "/kind/entertainment"
|
||||||
|
to = "/kind/entertainment-and-media-apps/"
|
||||||
|
status = 301
|
||||||
|
|
||||||
|
[[redirects]]
|
||||||
|
from = "/kind/photo-tools"
|
||||||
|
to = "/kind/photo-and-graphic-tools/"
|
||||||
|
status = 301
|
||||||
|
|
||||||
|
[[redirects]]
|
||||||
|
from = "/。"
|
||||||
|
to = "/"
|
||||||
|
status = 301
|
||||||
|
|
||||||
|
[[redirects]]
|
||||||
|
from = "/%E3%80%82"
|
||||||
|
to = "/"
|
||||||
|
status = 301
|
||||||
|
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
const { builder } = require("@netlify/functions")
|
|
||||||
|
|
||||||
async function myfunction(event, context) {
|
|
||||||
return {
|
|
||||||
statusCode: 200,
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "text/html",
|
|
||||||
},
|
|
||||||
body: `
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<body>
|
|
||||||
Hello World
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
`,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.handler = builder(myfunction);
|
|
||||||
54
netlify/functions/eleventy-builder/index.js
Normal file
54
netlify/functions/eleventy-builder/index.js
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
const { EleventyServerless } = require("@11ty/eleventy");
|
||||||
|
|
||||||
|
// Explicit dependencies for the bundler from config file and global data.
|
||||||
|
// The file is generated by the Eleventy Serverless Bundler Plugin.
|
||||||
|
require("./eleventy-bundler-modules.js");
|
||||||
|
|
||||||
|
async function handler(event) {
|
||||||
|
|
||||||
|
console.log('event.path', event.path)
|
||||||
|
|
||||||
|
let elev = new EleventyServerless("eleventy-builder", {
|
||||||
|
path: event.path,
|
||||||
|
query: event.queryStringParameters,
|
||||||
|
inputDir: ".",
|
||||||
|
functionsDir: "./netlify/functions/",
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
return {
|
||||||
|
statusCode: 200,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "text/html; charset=UTF-8",
|
||||||
|
},
|
||||||
|
body: await elev.render(),
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
// Only console log for matching serverless paths
|
||||||
|
// (otherwise you’ll see a bunch of BrowserSync 404s for non-dynamic URLs during --serve)
|
||||||
|
if (elev.isServerlessUrl(event.path)) {
|
||||||
|
console.log("Serverless Error:", error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
statusCode: error.httpStatusCode || 500,
|
||||||
|
body: JSON.stringify(
|
||||||
|
{
|
||||||
|
error: error.message,
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
2
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Choose one:
|
||||||
|
// * Runs on each request: AWS Lambda (or Netlify Function)
|
||||||
|
// * Runs on first request only: Netlify On-demand Builder
|
||||||
|
// (don’t forget to `npm install @netlify/functions`)
|
||||||
|
|
||||||
|
// exports.handler = handler;
|
||||||
|
|
||||||
|
const { builder } = require("@netlify/functions");
|
||||||
|
exports.handler = builder(handler);
|
||||||
Loading…
Add table
Add a link
Reference in a new issue