forked from cf-pages/Telegraph-Image
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrating Cloudflare Pages Function as backend (cf-pages#1)
* update * Use Cloudflare Page Function as Backend, no need to deploy Cloudflare Workers separately.
- Loading branch information
Showing
5 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package-lock.json | ||
_nuxt/b46e75617207ae5013d0.js | ||
node_modules | ||
package.json |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export async function onRequest(context) { | ||
// Contents of context object | ||
const { | ||
request, // same as existing Worker API | ||
env, // same as existing Worker API | ||
params, // if filename includes [id] or [[path]] | ||
waitUntil, // same as ctx.waitUntil in existing Worker API | ||
next, // used for middleware or to fetch assets | ||
data, // arbitrary space for passing data between middlewares | ||
} = context; | ||
const res = await fetch(`https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=5`); | ||
const bing_data = await res.json(); | ||
const return_data={ | ||
"status":true, | ||
"message":"操作成功", | ||
"data": bing_data.images | ||
} | ||
const info = JSON.stringify(return_data); | ||
return new Response(info); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export async function onRequest(context) { // Contents of context object | ||
const { | ||
request, // same as existing Worker API | ||
env, // same as existing Worker API | ||
params, // if filename includes [id] or [[path]] | ||
waitUntil, // same as ctx.waitUntil in existing Worker API | ||
next, // used for middleware or to fetch assets | ||
data, // arbitrary space for passing data between middlewares | ||
} = context; | ||
context.request | ||
const url = new URL(request.url); | ||
const response = fetch('https://telegra.ph/' + url.pathname + url.search, { | ||
method: request.method, | ||
headers: request.headers, | ||
body: request.body, | ||
}); | ||
return response; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export async function onRequestPost(context) { // Contents of context object | ||
const { | ||
request, // same as existing Worker API | ||
env, // same as existing Worker API | ||
params, // if filename includes [id] or [[path]] | ||
waitUntil, // same as ctx.waitUntil in existing Worker API | ||
next, // used for middleware or to fetch assets | ||
data, // arbitrary space for passing data between middlewares | ||
} = context; | ||
context.request | ||
const url = new URL(request.url); | ||
const response = fetch('https://telegra.ph/' + url.pathname + url.search, { | ||
method: request.method, | ||
headers: request.headers, | ||
body: request.body, | ||
}); | ||
return response; | ||
} | ||
|