Skip to content

Commit

Permalink
合并:新增可设置CORS跨域访问
Browse files Browse the repository at this point in the history
Merge pull request #10 from guobao2333/dev
  • Loading branch information
guobao2333 authored Sep 3, 2024
2 parents 621f573 + 6d3eafe commit 038f37f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/docker-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Docker Image CI

on:
push:
branches: [ "main" ]
paths: [ '**.js' ]
branches: [ 'main' ]
pull_request:
branches: [ "main" ]

Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ DeepLX 免费翻译API**函数部署版**,与原项目[DeepLX](https://github.
**Click `Star` if you like!! thanks❤️**

## Major Changes | 重大改变
> *vvvvery big changes🤣

如果您在这之前不使用本项目,此部分可以跳过。
1. 新增了docker部署支持
Expand All @@ -32,8 +31,8 @@ DeepLX 免费翻译API**函数部署版**,与原项目[DeepLX](https://github.
[![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/guobao2333/DeepLX-Serverless) -->

因维护者我有多个仓库需要维护,短时间内将无法对多平台部署方案进行兼容,您可以选择**自托管**方案。
✨项目当前没有任何需要填写的变量值,你只需要直接部署就可以用了,但在后续可能会添加。
因维护者我有多个仓库需要维护,短时间内将无法对多平台部署方案进行兼容,您可以先打开一个`issues`并选择**自托管**方案。
✨项目当前没有任何需要填写的变量值,但在后续可能会添加。

如果部署完成了,就可以开始使用啦!🎉
#### Docker
Expand Down Expand Up @@ -93,10 +92,10 @@ curl --location --request POST 'http://localhost:9000/translate' --header 'Conte
## Contribute | 贡献

> [!IMPORTANT]
> 由于我已对`main`分支做出限制,所以
> **在您做出贡献之前,请先切换到`dev`分支!!**
> 因为解决分支冲突真的很麻烦!
本人因时间(和各种各样的)原因,故无法及时对您的贡献进行测试,所以您需要**自行测试**
本人因时间(和各种各样的)原因,故无法及时对您的贡献进行测试,所以您还需要**自行测试**

## Star History

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"dependencies": {
"axios": "^1.6.3",
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"express": "^4.18.2",
"lodash": "^4.17.21",
"node-fetch": "^3.3.2",
Expand Down
17 changes: 13 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import express from 'express';
import cors from 'cors';
import bodyParser from 'body-parser';
import { translate } from './translate.js';

const app = express();
const PORT = 9000;
const allowAlternative = true;
const app = express(),
PORT = 9000,
allowAlternative = true,
CORS = {
origin: false, // 还支持指定多个域名或正则表达式
methods: 'GET,POST',
allowedHeaders: 'Content-Type',
preflightContinue: false
};

app.use(cors(CORS));
app.use(bodyParser.json());

// 为了方便兼容多平台才这样写
app.post('/translate', async (req, res) => await post(req, res));
app.get('/', async (req, res) => await get(req, res));
Expand Down Expand Up @@ -58,7 +67,7 @@ async function post(req, res) {
async function get(req, res) {
res.json({
code: 200,
message: "Welcome to the DeepL Free API. Please POST to '/translate'. Visit 'https://github.com/OwO-Network/DeepLX' and 'https://github.com/guobao2333/DeepLX-Serverless' for more information."
message: "Welcome to the DeepL Free API. Please POST to '/translate'. Visit 'https://github.com/guobao2333/DeepLX-Serverless' for more information."
});
};

Expand Down

0 comments on commit 038f37f

Please sign in to comment.