chatyou commited on
Commit
e0a7f38
·
verified ·
1 Parent(s): 88f43bf

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +10 -5
index.js CHANGED
@@ -1,10 +1,12 @@
 
1
  const fetch = require('node-fetch');
2
  const FormData = require('form-data');
3
  const sharp = require('sharp');
4
 
5
- async function onRequest(req, res) {
6
- const url = new URL(req.url, `http://${req.headers.host}`);
7
- const imageUrl = url.searchParams.get('q');
 
8
 
9
  if (!imageUrl) {
10
  return res.status(400).send('');
@@ -50,6 +52,9 @@ async function onRequest(req, res) {
50
  console.error('压缩图像时出错:', error);
51
  res.status(500).send('');
52
  }
53
- }
54
 
55
- module.exports = { onRequest };
 
 
 
 
1
+ const express = require('express');
2
  const fetch = require('node-fetch');
3
  const FormData = require('form-data');
4
  const sharp = require('sharp');
5
 
6
+ const app = express();
7
+
8
+ app.get('/resize', async (req, res) => {
9
+ const imageUrl = req.query.q;
10
 
11
  if (!imageUrl) {
12
  return res.status(400).send('');
 
52
  console.error('压缩图像时出错:', error);
53
  res.status(500).send('');
54
  }
55
+ });
56
 
57
+ const PORT = process.env.PORT || 3000;
58
+ app.listen(PORT, () => {
59
+ console.log(`Server is running on port ${PORT}`);
60
+ });