Skip to content

Commit beb3990

Browse files
committed
Add test7 + test8 using eval
1 parent cec3e27 commit beb3990

File tree

12 files changed

+3740
-10
lines changed

12 files changed

+3740
-10
lines changed

next.config.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
11
module.exports = {
22
target: "serverless",
3-
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
4-
// Note: we provide webpack above so you should not `require` it
5-
// Perform customizations to webpack config
6-
config.plugins.push(new webpack.IgnorePlugin(/@prisma/));
7-
8-
// Important: return the modified config
9-
return config;
10-
},
113
};

out_functions/next_api_test7/nextJsPage.js

Lines changed: 1769 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// TEMPLATE: This file will be copied to the Netlify functions directory when
2+
// running next-on-netlify
3+
4+
// Compatibility wrapper for NextJS page
5+
const compat = require("next-aws-lambda");
6+
// Load the NextJS page
7+
const page = require("./nextJsPage");
8+
9+
// next-aws-lambda is made for AWS. There are some minor differences between
10+
// Netlify and AWS which we resolve here.
11+
const callbackHandler = (callback) =>
12+
// The callbackHandler wraps the callback
13+
(argument, response) => {
14+
// Convert header values to string. Netlify does not support integers as
15+
// header values. See: https://github.com/netlify/cli/issues/451
16+
Object.keys(response.multiValueHeaders).forEach((key) => {
17+
response.multiValueHeaders[key] = response.multiValueHeaders[
18+
key
19+
].map((value) => String(value));
20+
});
21+
22+
// Invoke callback
23+
callback(argument, response);
24+
};
25+
26+
exports.handler = (event, context, callback) => {
27+
// Enable support for base64 encoding.
28+
// This is used by next-aws-lambda to determine whether to encode the response
29+
// body as base64.
30+
if (!process.env.hasOwnProperty("BINARY_SUPPORT")) {
31+
process.env.BINARY_SUPPORT = "yes";
32+
}
33+
34+
// When running on netlify, the header "host" is not set in
35+
// multiValueHeaders so we manually set it here.
36+
// TO-DO: @lindsaylevine/@cassidoo remove after netlify supports internally
37+
if(!event.multiValueHeaders.hasOwnProperty('host')) {
38+
event.multiValueHeaders['host'] = [event.headers['host']]
39+
}
40+
41+
// Get the request URL
42+
const { path } = event;
43+
console.log("[request]", path);
44+
45+
// Render the page
46+
compat(page)(
47+
{
48+
...event,
49+
// Required. Otherwise, compat() will complain
50+
requestContext: {},
51+
},
52+
context,
53+
// Wrap the Netlify callback, so that we can resolve differences between
54+
// Netlify and AWS (which next-aws-lambda optimizes for)
55+
callbackHandler(callback)
56+
);
57+
};

out_functions/next_api_test8/nextJsPage.js

Lines changed: 1769 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// TEMPLATE: This file will be copied to the Netlify functions directory when
2+
// running next-on-netlify
3+
if (false) {
4+
const { PrismaClient } = require("@prisma/client");
5+
}
6+
7+
// Compatibility wrapper for NextJS page
8+
const compat = require("next-aws-lambda");
9+
// Load the NextJS page
10+
const page = require("./nextJsPage");
11+
12+
// next-aws-lambda is made for AWS. There are some minor differences between
13+
// Netlify and AWS which we resolve here.
14+
const callbackHandler = (callback) =>
15+
// The callbackHandler wraps the callback
16+
(argument, response) => {
17+
// Convert header values to string. Netlify does not support integers as
18+
// header values. See: https://github.com/netlify/cli/issues/451
19+
Object.keys(response.multiValueHeaders).forEach((key) => {
20+
response.multiValueHeaders[key] = response.multiValueHeaders[
21+
key
22+
].map((value) => String(value));
23+
});
24+
25+
// Invoke callback
26+
callback(argument, response);
27+
};
28+
29+
exports.handler = (event, context, callback) => {
30+
// Enable support for base64 encoding.
31+
// This is used by next-aws-lambda to determine whether to encode the response
32+
// body as base64.
33+
if (!process.env.hasOwnProperty("BINARY_SUPPORT")) {
34+
process.env.BINARY_SUPPORT = "yes";
35+
}
36+
37+
// When running on netlify, the header "host" is not set in
38+
// multiValueHeaders so we manually set it here.
39+
// TO-DO: @lindsaylevine/@cassidoo remove after netlify supports internally
40+
if (!event.multiValueHeaders.hasOwnProperty("host")) {
41+
event.multiValueHeaders["host"] = [event.headers["host"]];
42+
}
43+
44+
// Get the request URL
45+
const { path } = event;
46+
console.log("[request]", path);
47+
48+
// Render the page
49+
compat(page)(
50+
{
51+
...event,
52+
// Required. Otherwise, compat() will complain
53+
requestContext: {},
54+
},
55+
context,
56+
// Wrap the Netlify callback, so that we can resolve differences between
57+
// Netlify and AWS (which next-aws-lambda optimizes for)
58+
callbackHandler(callback)
59+
);
60+
};

out_publish/404.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width"/><meta charSet="utf-8"/><title>404: This page could not be found</title><noscript data-n-css="true"></noscript><link rel="preload" href="/_next/static/chunks/main-cbfc2a92a0825e0b63bf.js" as="script"/><link rel="preload" href="/_next/static/chunks/webpack-e067438c4cf4ef2ef178.js" as="script"/><link rel="preload" href="/_next/static/chunks/framework.1daf1ec1ecf144ee9147.js" as="script"/><link rel="preload" href="/_next/static/chunks/commons.c6a8bf6988d7f4eaa7c5.js" as="script"/><link rel="preload" href="/_next/static/chunks/pages/_app-24382224f10887fed77f.js" as="script"/></head><body><div id="__next"><div style="color:#000;background:#fff;font-family:-apple-system, BlinkMacSystemFont, Roboto, &quot;Segoe UI&quot;, &quot;Fira Sans&quot;, Avenir, &quot;Helvetica Neue&quot;, &quot;Lucida Grande&quot;, sans-serif;height:100vh;text-align:center;display:flex;flex-direction:column;align-items:center;justify-content:center"><div><style>body { margin: 0 }</style><h1 style="display:inline-block;border-right:1px solid rgba(0, 0, 0,.3);margin:0;margin-right:20px;padding:10px 23px 10px 0;font-size:24px;font-weight:500;vertical-align:top">404</h1><div style="display:inline-block;text-align:left;line-height:49px;height:49px;vertical-align:middle"><h2 style="font-size:14px;font-weight:normal;line-height:inherit;margin:0;padding:0">This page could not be found<!-- -->.</h2></div></div></div></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"statusCode":404}},"page":"/_error","query":{},"buildId":"p2efC3emMOdm7EKNnFXQJ","runtimeConfig":{},"nextExport":true,"isFallback":false,"gip":true,"head":[["meta",{"name":"viewport","content":"width=device-width"}],["meta",{"charSet":"utf-8"}],["title",{"children":"404: This page could not be found"}]]}</script><script nomodule="" src="/_next/static/chunks/polyfills-fd3597f65753721f35bc.js"></script><script src="/_next/static/chunks/main-cbfc2a92a0825e0b63bf.js" async=""></script><script src="/_next/static/chunks/webpack-e067438c4cf4ef2ef178.js" async=""></script><script src="/_next/static/chunks/framework.1daf1ec1ecf144ee9147.js" async=""></script><script src="/_next/static/chunks/commons.c6a8bf6988d7f4eaa7c5.js" async=""></script><script src="/_next/static/chunks/pages/_app-24382224f10887fed77f.js" async=""></script><script src="/_next/static/p2efC3emMOdm7EKNnFXQJ/_buildManifest.js" async=""></script><script src="/_next/static/p2efC3emMOdm7EKNnFXQJ/_ssgManifest.js" async=""></script></body></html>
1+
<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width"/><meta charSet="utf-8"/><title>404: This page could not be found</title><noscript data-n-css="true"></noscript><link rel="preload" href="/_next/static/chunks/main-cbfc2a92a0825e0b63bf.js" as="script"/><link rel="preload" href="/_next/static/chunks/webpack-e067438c4cf4ef2ef178.js" as="script"/><link rel="preload" href="/_next/static/chunks/framework.1daf1ec1ecf144ee9147.js" as="script"/><link rel="preload" href="/_next/static/chunks/commons.c6a8bf6988d7f4eaa7c5.js" as="script"/><link rel="preload" href="/_next/static/chunks/pages/_app-24382224f10887fed77f.js" as="script"/></head><body><div id="__next"><div style="color:#000;background:#fff;font-family:-apple-system, BlinkMacSystemFont, Roboto, &quot;Segoe UI&quot;, &quot;Fira Sans&quot;, Avenir, &quot;Helvetica Neue&quot;, &quot;Lucida Grande&quot;, sans-serif;height:100vh;text-align:center;display:flex;flex-direction:column;align-items:center;justify-content:center"><div><style>body { margin: 0 }</style><h1 style="display:inline-block;border-right:1px solid rgba(0, 0, 0,.3);margin:0;margin-right:20px;padding:10px 23px 10px 0;font-size:24px;font-weight:500;vertical-align:top">404</h1><div style="display:inline-block;text-align:left;line-height:49px;height:49px;vertical-align:middle"><h2 style="font-size:14px;font-weight:normal;line-height:inherit;margin:0;padding:0">This page could not be found<!-- -->.</h2></div></div></div></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"statusCode":404}},"page":"/_error","query":{},"buildId":"jOJoHJujuAfCPP_etiW0e","runtimeConfig":{},"nextExport":true,"isFallback":false,"gip":true,"head":[["meta",{"name":"viewport","content":"width=device-width"}],["meta",{"charSet":"utf-8"}],["title",{"children":"404: This page could not be found"}]]}</script><script nomodule="" src="/_next/static/chunks/polyfills-fd3597f65753721f35bc.js"></script><script src="/_next/static/chunks/main-cbfc2a92a0825e0b63bf.js" async=""></script><script src="/_next/static/chunks/webpack-e067438c4cf4ef2ef178.js" async=""></script><script src="/_next/static/chunks/framework.1daf1ec1ecf144ee9147.js" async=""></script><script src="/_next/static/chunks/commons.c6a8bf6988d7f4eaa7c5.js" async=""></script><script src="/_next/static/chunks/pages/_app-24382224f10887fed77f.js" async=""></script><script src="/_next/static/jOJoHJujuAfCPP_etiW0e/_buildManifest.js" async=""></script><script src="/_next/static/jOJoHJujuAfCPP_etiW0e/_ssgManifest.js" async=""></script></body></html>

out_publish/_next/static/UHlDKdn1OHVK0029zXVp7/_buildManifest.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
self.__SSG_MANIFEST=new Set;self.__SSG_MANIFEST_CB&&self.__SSG_MANIFEST_CB()

out_publish/_next/static/jOJoHJujuAfCPP_etiW0e/_buildManifest.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
self.__SSG_MANIFEST=new Set;self.__SSG_MANIFEST_CB&&self.__SSG_MANIFEST_CB()

out_publish/_redirects

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Next-on-Netlify Redirects
22
/api/test /.netlify/functions/next_api_test 200
33
/api/test3 /.netlify/functions/next_api_test3 200
4-
/api/test5 /.netlify/functions/next_api_test5 200
4+
/api/test5 /.netlify/functions/next_api_test5 200
5+
/api/test7 /.netlify/functions/next_api_test7 200

pages/api/test7.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
const { PrismaClient } = eval('require("@prisma/client")');
2+
const prisma = new PrismaClient();
3+
4+
export default async function handler(req, res) {
5+
try {
6+
await Promise.all([prisma.profile.deleteMany(), prisma.post.deleteMany()]);
7+
await prisma.user.deleteMany();
8+
9+
const createdUser = await prisma.user.create({
10+
data: seedUser,
11+
});
12+
13+
const createdUser2 = await prisma.user.create({
14+
data: seedUser2,
15+
});
16+
17+
res.statusCode = 200;
18+
res.json({ success: "true" });
19+
} catch (error) {
20+
console.error(error);
21+
res.statusCode = 500;
22+
res.json({ error: error.message });
23+
}
24+
}
25+
26+
const seedUser = {
27+
28+
name: "Jane",
29+
profile: {
30+
create: {
31+
bio: "Health Enthusiast",
32+
},
33+
},
34+
posts: {
35+
create: [
36+
{
37+
title:
38+
"Comparing Database Types: How Database Types Evolved to Meet Different Needs",
39+
content:
40+
"https://www.prisma.io/blog/comparison-of-database-models-1iz9u29nwn37/",
41+
},
42+
{
43+
title: "Analysing Sleep Patterns: The Quantified Self",
44+
content: "https://quantifiedself.com/get-started/",
45+
},
46+
{
47+
title: "Prisma 2 Docs",
48+
content: "https://www.prisma.io/docs/",
49+
},
50+
],
51+
},
52+
};
53+
54+
const seedUser2 = {
55+
56+
name: "Toru Takemitsu",
57+
profile: {
58+
create: {
59+
bio: "Musician",
60+
},
61+
},
62+
posts: {
63+
create: [
64+
{
65+
title: "Requiem for String Orchestra",
66+
content: "",
67+
},
68+
{
69+
title: "Music of Tree",
70+
content: "",
71+
},
72+
{
73+
title: "Waves for clarinet, horn, two trombones and bass drum ",
74+
content: "",
75+
},
76+
],
77+
},
78+
};

0 commit comments

Comments
 (0)