Spaces:
Sleeping
Sleeping
Commit ·
4c209d0
1
Parent(s): b1a12e9
first test
Browse files- .gitignore +1 -0
- Dockerfile +11 -0
- jsconfig.json +22 -0
- package-lock.json +0 -0
- package.json +51 -0
- server.js +29 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
node_modules
|
Dockerfile
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM node:22-bookworm
|
| 2 |
+
EXPOSE 7860/tcp
|
| 3 |
+
|
| 4 |
+
USER node
|
| 5 |
+
WORKDIR /home/node
|
| 6 |
+
COPY --chown=node package.json /home/node
|
| 7 |
+
COPY --chown=node server.js /home/node
|
| 8 |
+
|
| 9 |
+
RUN ["/bin/bash", "-c", "npm install"]
|
| 10 |
+
|
| 11 |
+
CMD ["/bin/bash", "-c", "npm start"]
|
jsconfig.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"include": [
|
| 3 |
+
"server.js"
|
| 4 |
+
],
|
| 5 |
+
"compilerOptions": {
|
| 6 |
+
"target": "es2023",
|
| 7 |
+
"module": "es2022",
|
| 8 |
+
"allowJs": true,
|
| 9 |
+
"checkJs": true,
|
| 10 |
+
"allowUnreachableCode": false,
|
| 11 |
+
"allowUnusedLabels": false,
|
| 12 |
+
"exactOptionalPropertyTypes": true,
|
| 13 |
+
"noImplicitOverride": true,
|
| 14 |
+
"noImplicitReturns": true,
|
| 15 |
+
"noPropertyAccessFromIndexSignature": true,
|
| 16 |
+
"noUncheckedIndexedAccess": true,
|
| 17 |
+
"noUnusedLocals": true,
|
| 18 |
+
"noUnusedParameters": true,
|
| 19 |
+
"strict": true,
|
| 20 |
+
"noEmit": true
|
| 21 |
+
}
|
| 22 |
+
}
|
package-lock.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@hackmaster/hf_test",
|
| 3 |
+
"version": "0.0.1",
|
| 4 |
+
"description": "HF test",
|
| 5 |
+
"homepage": "https://huggingface.co/spaces/codename-mute/test",
|
| 6 |
+
"bugs": {
|
| 7 |
+
"url": "https://huggingface.co/spaces/codename-mute/test",
|
| 8 |
+
"email": "codename.mute@proton.me"
|
| 9 |
+
},
|
| 10 |
+
"license": "SEE LICENSE IN LICENSE",
|
| 11 |
+
"author": "Mute <codename.mute@proton.me> ()",
|
| 12 |
+
"repository": {
|
| 13 |
+
"type": "git",
|
| 14 |
+
"url": "git+https://huggingface.co/spaces/codename-mute/test"
|
| 15 |
+
},
|
| 16 |
+
"config": {},
|
| 17 |
+
"devDependencies": {
|
| 18 |
+
"typescript": "^5.5.4",
|
| 19 |
+
"xo": "^0.59.3"
|
| 20 |
+
},
|
| 21 |
+
"type": "module",
|
| 22 |
+
"eslintConfig": {
|
| 23 |
+
"root": true,
|
| 24 |
+
"extends": [
|
| 25 |
+
"xo",
|
| 26 |
+
"xo-typescript",
|
| 27 |
+
"plugin:unicorn/recommended"
|
| 28 |
+
],
|
| 29 |
+
"parser": "@typescript-eslint/parser",
|
| 30 |
+
"parserOptions": {
|
| 31 |
+
"project": [
|
| 32 |
+
"./jsconfig.json"
|
| 33 |
+
]
|
| 34 |
+
},
|
| 35 |
+
"plugins": [
|
| 36 |
+
"@typescript-eslint",
|
| 37 |
+
"unicorn"
|
| 38 |
+
],
|
| 39 |
+
"rules": {
|
| 40 |
+
"@typescript-eslint/brace-style": "off",
|
| 41 |
+
"@typescript-eslint/naming-convention": "off",
|
| 42 |
+
"@typescript-eslint/no-confusing-void-expression": ["error", {"ignoreVoidOperator": true}],
|
| 43 |
+
"@typescript-eslint/no-meaningless-void-operator": "off",
|
| 44 |
+
"@typescript-eslint/no-unused-expressions": "off",
|
| 45 |
+
"@typescript-eslint/semi": "off",
|
| 46 |
+
"max-statements-per-line": "off",
|
| 47 |
+
"no-void": "off",
|
| 48 |
+
"fake/fuck-commas": "off"
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
}
|
server.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {createServer} from 'node:http'
|
| 2 |
+
|
| 3 |
+
const config = {host: '0.0.0.0', port: 7860}
|
| 4 |
+
|
| 5 |
+
const h_cors = {
|
| 6 |
+
'Access-Control-Max-Age': '86400',
|
| 7 |
+
'Access-Control-Allow-Private-Network': 'true',
|
| 8 |
+
'Access-Control-Allow-Origin': '*',
|
| 9 |
+
'Access-Control-Allow-Methods': 'GET, OPTIONS',
|
| 10 |
+
'Access-Control-Allow-Headers': '*',
|
| 11 |
+
// 'Access-Control-Allow-Credentials': 'false', // omit this header to disallow
|
| 12 |
+
}
|
| 13 |
+
const h_all = {
|
| 14 |
+
'Content-Type': 'text/javascript',
|
| 15 |
+
'Cache-Control': 'no-cache',
|
| 16 |
+
...h_cors
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
/** @type {Record<string,((request: import('node:http').ServerResponse) => void)>} */ const resp = {
|
| 20 |
+
GET(rx) { rx.writeHead(200, h_all); rx.write('Hello world') },
|
| 21 |
+
OPTIONS(rx) { rx.writeHead(204, h_cors) },
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
const server = createServer((rq, rx) => {
|
| 25 |
+
const handler = resp[rq.method ?? '']
|
| 26 |
+
handler !== undefined && (new URL(`http://${config.host}:${config.port}${rq.url}`)).pathname === '/' ? handler(rx) : rx.writeHead(400)
|
| 27 |
+
rx.end(() => void console.log('%s %d %s %s', (new Date()).toISOString(), rx.statusCode, rq.method, rq.url))
|
| 28 |
+
})
|
| 29 |
+
server.listen(config.port, config.host, () => void console.log(`Server started at http://${config.host}:${config.port}`))
|