-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: add SvelteKit example (#5181)
- Loading branch information
Showing
19 changed files
with
381 additions
and
711 deletions.
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 |
---|---|---|
|
@@ -4,5 +4,6 @@ node_modules/ | |
*.cjs | ||
*.mjs | ||
!private/js2ts/* | ||
!examples/svelte-example/* | ||
*.lock | ||
CHANGELOG.md |
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 |
---|---|---|
@@ -1,6 +1,12 @@ | ||
/node_modules/ | ||
/uploads/ | ||
/public/build/ | ||
|
||
.DS_Store | ||
package-lock.json | ||
/build/ | ||
/.svelte-kit | ||
/package | ||
.env | ||
.env.* | ||
!.env.example | ||
vite.config.js.timestamp-* | ||
vite.config.ts.timestamp-* |
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
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,64 @@ | ||
#!/usr/bin/env node | ||
|
||
/* eslint-disable no-console */ | ||
|
||
import http from 'node:http' | ||
import { fileURLToPath } from 'node:url' | ||
import { mkdir } from 'node:fs/promises' | ||
|
||
import formidable from 'formidable' | ||
|
||
const UPLOAD_DIR = new URL('./uploads/', import.meta.url) | ||
|
||
await mkdir(UPLOAD_DIR, { recursive: true }) | ||
|
||
http | ||
.createServer((req, res) => { | ||
const headers = { | ||
'Content-Type': 'application/json', | ||
'Access-Control-Allow-Origin': '*', | ||
'Access-Control-Allow-Methods': 'OPTIONS, POST, GET', | ||
'Access-Control-Max-Age': 2592000, // 30 days | ||
/** add other headers as per requirement */ | ||
} | ||
|
||
if (req.method === 'OPTIONS') { | ||
res.writeHead(204, headers) | ||
res.end() | ||
return | ||
} | ||
if (req.url === '/upload' && req.method.toLowerCase() === 'post') { | ||
// parse a file upload | ||
const form = formidable({ | ||
keepExtensions: true, | ||
uploadDir: fileURLToPath(UPLOAD_DIR), | ||
}) | ||
|
||
form.parse(req, (err, fields, files) => { | ||
res.writeHead(200, headers) | ||
if (err) { | ||
console.log('some error', err) | ||
res.write(JSON.stringify(err)) | ||
} else { | ||
for (const { | ||
filepath, | ||
originalFilename, | ||
mimetype, | ||
size, | ||
} of files.files) { | ||
console.log('saved file', { | ||
filepath, | ||
originalFilename, | ||
mimetype, | ||
size, | ||
}) | ||
} | ||
res.write(JSON.stringify({ fields, files })) | ||
} | ||
res.end() | ||
}) | ||
} | ||
}) | ||
.listen(9967, () => { | ||
console.log('server started') | ||
}) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.