viocha commited on
Commit
14d71e0
·
1 Parent(s): 4f848ae

初次提交

Browse files
.idea/.gitignore ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Editor-based HTTP Client requests
5
+ /httpRequests/
6
+ # Datasource local storage ignored files
7
+ /dataSources/
8
+ /dataSources.local.xml
.idea/codeStyles/codeStyleConfig.xml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ <component name="ProjectCodeStyleConfiguration">
2
+ <state>
3
+ <option name="PREFERRED_PROJECT_CODE_STYLE" value="IdeaCodeStyle" />
4
+ </state>
5
+ </component>
.idea/copilot.data.migration.agent.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="AgentMigrationStateService">
4
+ <option name="migrationStatus" value="COMPLETED" />
5
+ </component>
6
+ </project>
.idea/copilot.data.migration.edit.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="EditMigrationStateService">
4
+ <option name="migrationStatus" value="COMPLETED" />
5
+ </component>
6
+ </project>
.idea/inspectionProfiles/Project_Default.xml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="GoCommentStart" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
5
+ <inspection_tool class="GoContextTodo" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
6
+ <inspection_tool class="GoMixedReceiverTypes" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
7
+ <inspection_tool class="GoPreferNilSlice" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
8
+ <inspection_tool class="PyMethodFirstArgAssignmentInspection" enabled="false" level="WARNING" enabled_by_default="false" />
9
+ <inspection_tool class="PyPep8Inspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
10
+ </profile>
11
+ </component>
.idea/misc.xml ADDED
@@ -0,0 +1,251 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="AhkProjectSettings">
4
+ <option name="defaultAhkSdk" value="AutoHotkey v2.0.10" />
5
+ </component>
6
+ <component name="FormatOnSaveOptions">
7
+ <option name="myRunOnSave" value="false" />
8
+ </component>
9
+ <component name="GOROOT" url="file://$PROJECT_DIR$/../../../../Program Files/Go" />
10
+ <component name="GoLibraries">
11
+ <option name="indexEntireGoPath" value="true" />
12
+ </component>
13
+ <component name="GoVcsConfiguration">
14
+ <option name="GO_FMT" value="false" />
15
+ </component>
16
+ <component name="ProjectInspectionProfilesVisibleTreeState">
17
+ <entry key="Project Default">
18
+ <profile-state>
19
+ <expanded-state>
20
+ <State>
21
+ <id>Abstraction issuesJava</id>
22
+ </State>
23
+ <State>
24
+ <id>Angular</id>
25
+ </State>
26
+ <State>
27
+ <id>BibTeX</id>
28
+ </State>
29
+ <State>
30
+ <id>CSS</id>
31
+ </State>
32
+ <State>
33
+ <id>Class structureJava</id>
34
+ </State>
35
+ <State>
36
+ <id>ClassNaming conventionsJava</id>
37
+ </State>
38
+ <State>
39
+ <id>Code maturityJava</id>
40
+ </State>
41
+ <State>
42
+ <id>Code maturityLaTeX</id>
43
+ </State>
44
+ <State>
45
+ <id>Code style issuesGo</id>
46
+ </State>
47
+ <State>
48
+ <id>Code style issuesJava</id>
49
+ </State>
50
+ <State>
51
+ <id>Control flow issuesJava</id>
52
+ </State>
53
+ <State>
54
+ <id>DOM issuesJavaScript and TypeScript</id>
55
+ </State>
56
+ <State>
57
+ <id>Declaration redundancyGo</id>
58
+ </State>
59
+ <State>
60
+ <id>Declaration redundancyGo modules</id>
61
+ </State>
62
+ <State>
63
+ <id>Dependency issues (go list -m -u)Go modules</id>
64
+ </State>
65
+ <State>
66
+ <id>Dockerfile</id>
67
+ </State>
68
+ <State>
69
+ <id>EditorConfig</id>
70
+ </State>
71
+ <State>
72
+ <id>EmbeddedPerformanceJava</id>
73
+ </State>
74
+ <State>
75
+ <id>EncapsulationJava</id>
76
+ </State>
77
+ <State>
78
+ <id>Error handlingJava</id>
79
+ </State>
80
+ <State>
81
+ <id>Flow type checkerJavaScript and TypeScript</id>
82
+ </State>
83
+ <State>
84
+ <id>General</id>
85
+ </State>
86
+ <State>
87
+ <id>GeneralGo modules</id>
88
+ </State>
89
+ <State>
90
+ <id>GeneralJavaScript and TypeScript</id>
91
+ </State>
92
+ <State>
93
+ <id>Go</id>
94
+ </State>
95
+ <State>
96
+ <id>Go modules</id>
97
+ </State>
98
+ <State>
99
+ <id>ImportsJava</id>
100
+ </State>
101
+ <State>
102
+ <id>Inheritance issuesJava</id>
103
+ </State>
104
+ <State>
105
+ <id>Internationalization</id>
106
+ </State>
107
+ <State>
108
+ <id>InternationalizationJava</id>
109
+ </State>
110
+ <State>
111
+ <id>JSON and JSON5</id>
112
+ </State>
113
+ <State>
114
+ <id>JVM languages</id>
115
+ </State>
116
+ <State>
117
+ <id>Java</id>
118
+ </State>
119
+ <State>
120
+ <id>Java 23Java language level migration aidsJava</id>
121
+ </State>
122
+ <State>
123
+ <id>Java 8Java language level migration aidsJava</id>
124
+ </State>
125
+ <State>
126
+ <id>Java interop issuesKotlin</id>
127
+ </State>
128
+ <State>
129
+ <id>Java language level migration aidsJava</id>
130
+ </State>
131
+ <State>
132
+ <id>JavaScript and TypeScript</id>
133
+ </State>
134
+ <State>
135
+ <id>JavadocJava</id>
136
+ </State>
137
+ <State>
138
+ <id>Kotlin</id>
139
+ </State>
140
+ <State>
141
+ <id>LaTeX</id>
142
+ </State>
143
+ <State>
144
+ <id>LoggingJVM languages</id>
145
+ </State>
146
+ <State>
147
+ <id>MemoryJava</id>
148
+ </State>
149
+ <State>
150
+ <id>Naming conventionsJava</id>
151
+ </State>
152
+ <State>
153
+ <id>Naming conventionsKotlin</id>
154
+ </State>
155
+ <State>
156
+ <id>OpenAPI specifications</id>
157
+ </State>
158
+ <State>
159
+ <id>Other problemsKotlin</id>
160
+ </State>
161
+ <State>
162
+ <id>PerformanceJava</id>
163
+ </State>
164
+ <State>
165
+ <id>PortabilityJava</id>
166
+ </State>
167
+ <State>
168
+ <id>Potentially undesirable code constructsJavaScript and TypeScript</id>
169
+ </State>
170
+ <State>
171
+ <id>Probable bugsCSS</id>
172
+ </State>
173
+ <State>
174
+ <id>Probable bugsGo</id>
175
+ </State>
176
+ <State>
177
+ <id>Probable bugsJava</id>
178
+ </State>
179
+ <State>
180
+ <id>Probable bugsJavaScript and TypeScript</id>
181
+ </State>
182
+ <State>
183
+ <id>Probable bugsKotlin</id>
184
+ </State>
185
+ <State>
186
+ <id>Probable bugsLaTeX</id>
187
+ </State>
188
+ <State>
189
+ <id>Proofreading</id>
190
+ </State>
191
+ <State>
192
+ <id>Pyramid</id>
193
+ </State>
194
+ <State>
195
+ <id>Python</id>
196
+ </State>
197
+ <State>
198
+ <id>ReactJavaScript and TypeScript</id>
199
+ </State>
200
+ <State>
201
+ <id>Redundant code constructsLaTeX</id>
202
+ </State>
203
+ <State>
204
+ <id>SQL</id>
205
+ </State>
206
+ <State>
207
+ <id>SQL server</id>
208
+ </State>
209
+ <State>
210
+ <id>SecurityJava</id>
211
+ </State>
212
+ <State>
213
+ <id>Style issuesKotlin</id>
214
+ </State>
215
+ <State>
216
+ <id>Style issuesLaTeX</id>
217
+ </State>
218
+ <State>
219
+ <id>TestNGJava</id>
220
+ </State>
221
+ <State>
222
+ <id>Threading issuesJava</id>
223
+ </State>
224
+ <State>
225
+ <id>Try statement issuesJavaScript and TypeScript</id>
226
+ </State>
227
+ <State>
228
+ <id>TypeScriptJavaScript and TypeScript</id>
229
+ </State>
230
+ <State>
231
+ <id>Typesetting issuesLaTeX</id>
232
+ </State>
233
+ <State>
234
+ <id>VisibilityJava</id>
235
+ </State>
236
+ <State>
237
+ <id>XML</id>
238
+ </State>
239
+ </expanded-state>
240
+ </profile-state>
241
+ </entry>
242
+ </component>
243
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
244
+ <output url="file://$PROJECT_DIR$/out" />
245
+ </component>
246
+ <component name="VcsManagerConfiguration">
247
+ <option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
248
+ <option name="CHECK_NEW_TODO" value="false" />
249
+ <option name="NON_MODAL_COMMIT_POSTPONE_SLOW_CHECKS" value="false" />
250
+ </component>
251
+ </project>
.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/test-cors.iml" filepath="$PROJECT_DIR$/.idea/test-cors.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
.idea/test-cors.iml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="JAVA_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$" />
6
+ <orderEntry type="inheritedJdk" />
7
+ <orderEntry type="sourceFolder" forTests="false" />
8
+ </component>
9
+ </module>
.idea/vcs.xml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
6
+ </component>
7
+ </project>
Dockerfile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 使用 Node.js 22 的轻量级镜像作为基础
2
+ FROM node:22-alpine
3
+
4
+ # 在容器内创建一个工作目录
5
+ WORKDIR /usr/src/app
6
+
7
+ # 复制 package.json 和 package-lock.json (如果存在)
8
+ COPY package*.json ./
9
+
10
+ # 安装项目依赖
11
+ RUN npm install
12
+
13
+ # 复制应用源代码到工作目录
14
+ COPY . .
15
+
16
+ # Hugging Face Spaces 默认会暴露 7860 端口
17
+ EXPOSE 7860
18
+
19
+ # 容器启动时运行的命令
20
+ CMD [ "node", "app.js" ]
app.js ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import express from 'express';
2
+ import cors from 'cors';
3
+
4
+ const app = express();
5
+ // Hugging Face Spaces 默认使用 7860 端口
6
+ const PORT = process.env.PORT || 7860;
7
+
8
+ // 配置 CORS 中间件以允许所有来源的请求
9
+ app.use(cors());
10
+
11
+ // 定义一个中间件来为所有响应添加自定义响应头
12
+ app.use((req, res, next) => {
13
+ res.setHeader('X-Custom-Header-Test', 'HuggingFace-Express-App-Works');
14
+ next();
15
+ });
16
+
17
+ // 根路由,返回一个 HTML 页面
18
+ app.get('/', (req, res) => {
19
+ res.send(`
20
+ <!DOCTYPE html>
21
+ <html lang="en">
22
+ <head>
23
+ <meta charset="UTF-8">
24
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
25
+ <title>Express App on Hugging Face</title>
26
+ <style>
27
+ body { font-family: sans-serif; line-height: 1.6; padding: 2em; background-color: #f4f4f9; color: #333; }
28
+ .container { max-width: 800px; margin: auto; background: white; padding: 2em; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
29
+ h1 { color: #555; }
30
+ p { font-size: 1.1em; }
31
+ code { background-color: #eee; padding: 0.8em; border-radius: 4px; display: block; white-space: pre-wrap; word-wrap: break-word; cursor: pointer; }
32
+ .copy-notice { font-size: 0.9em; color: #888; margin-top: 0.5em; }
33
+ </style>
34
+ </head>
35
+ <body>
36
+ <div class="container">
37
+ <h1>Express.js 应用已成功部署!</h1>
38
+ <p>要测试 API,请打开浏览器的开发者工具(按 F12),切换到 "Console"(控制台)选项卡,然后粘贴并运行以下代码:</p>
39
+ <code id="fetch-code">fetch(window.location.origin + '/api')
40
+ .then(response => {
41
+ console.log('Status:', response.status);
42
+ console.log('Custom Header "X-Custom-Header-Test":', response.headers.get('X-Custom-Header-Test'));
43
+ return response.json();
44
+ })
45
+ .then(data => console.log('Data:', data))
46
+ .catch(error => console.error('Error:', error));</code>
47
+ <p class="copy-notice">点击上面的代码块即可复制。</p>
48
+ </div>
49
+ <script>
50
+ document.getElementById('fetch-code').addEventListener('click', function() {
51
+ navigator.clipboard.writeText(this.innerText).then(() => {
52
+ alert('代码已复制到剪贴板!');
53
+ }).catch(err => {
54
+ console.error('无法复制文本: ', err);
55
+ });
56
+ });
57
+ </script>
58
+ </body>
59
+ </html>
60
+ `);
61
+ });
62
+
63
+ // API 路由,返回 JSON 数据
64
+ app.get('/api', (req, res) => {
65
+ res.json({
66
+ message: 'API is working!',
67
+ timestamp: new Date().toISOString()
68
+ });
69
+ });
70
+
71
+ app.listen(PORT, () => {
72
+ console.log(`Server is running on port ${PORT}`);
73
+ });
package.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "huggingface-express-app-esm",
3
+ "version": "1.0.0",
4
+ "description": "An Express app with ES Modules deployed to Hugging Face Spaces.",
5
+ "main": "app.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "start": "node app.js"
9
+ },
10
+ "dependencies": {
11
+ "cors": "^2.8.5",
12
+ "express": "^4.18.2"
13
+ }
14
+ }