Initial commit. Files are uploaded to the filesystem.
This commit is contained in:
13
dist/web/files.js
vendored
Normal file
13
dist/web/files.js
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { uploadFiles } from '#src/files.js';
|
||||
export async function uploadFilesApi(req, res) {
|
||||
const files = req.files;
|
||||
const uploads = await uploadFiles(files.map((file) => ({
|
||||
fileName: file.originalname,
|
||||
encoding: file.encoding,
|
||||
mimetype: file.mimetype,
|
||||
tempName: file.filename,
|
||||
size: file.size,
|
||||
})), JSON.parse(req.body.options));
|
||||
res.send(uploads);
|
||||
}
|
||||
//# sourceMappingURL=files.js.map
|
||||
1
dist/web/files.js.map
vendored
Normal file
1
dist/web/files.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../src/web/files.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,GAAY,EAAE,GAAa;IAC/D,MAAM,KAAK,GAAG,GAAG,CAAC,KAA8B,CAAC;IAEjD,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACrD,QAAQ,EAAE,IAAI,CAAC,YAAY;QAC3B,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,IAAI,EAAE,IAAI,CAAC,IAAI;KAChB,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAEnC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACnB,CAAC"}
|
||||
5
dist/web/root.js
vendored
Normal file
5
dist/web/root.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
export const root = `${__dirname}/../..`;
|
||||
//# sourceMappingURL=root.js.map
|
||||
1
dist/web/root.js.map
vendored
Normal file
1
dist/web/root.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"root.js","sourceRoot":"","sources":["../../src/web/root.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAE1D,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,SAAS,QAAQ,CAAC"}
|
||||
55
dist/web/server.js
vendored
Normal file
55
dist/web/server.js
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
import config from 'config';
|
||||
import express from 'express';
|
||||
import bodyParser from 'express';
|
||||
import compression from 'compression';
|
||||
import { renderPage, createDevMiddleware } from 'vike/server';
|
||||
import multer from 'multer';
|
||||
import { root } from '#web/root.js';
|
||||
import { uploadFilesApi } from '#web/files.js';
|
||||
const isProduction = process.env.NODE_ENV === 'production';
|
||||
export async function initServer() {
|
||||
const app = express();
|
||||
// const upload = multer({ dest: './uploads' });
|
||||
const upload = multer({ dest: './uploads/temp' });
|
||||
app.use(compression());
|
||||
app.use(bodyParser.json());
|
||||
app.use(bodyParser.urlencoded());
|
||||
// Vite integration
|
||||
if (isProduction) {
|
||||
// In production, we need to serve our static assets ourselves.
|
||||
// (In dev, Vite's middleware serves our static assets.)
|
||||
const sirv = (await import('sirv')).default;
|
||||
app.use(sirv(`${root}/dist/client`));
|
||||
}
|
||||
else {
|
||||
const { devMiddleware } = await createDevMiddleware({ root });
|
||||
app.use(devMiddleware);
|
||||
}
|
||||
// app.post('/api/files', uploadFilesApi);
|
||||
app.post('/api/files', upload.array('files'), uploadFilesApi);
|
||||
// Vike middleware. It should always be our last middleware (because it's a
|
||||
// catch-all middleware superseding any middleware placed after it).
|
||||
app.get('*', async (req, res) => {
|
||||
const pageContextInit = {
|
||||
urlOriginal: req.originalUrl,
|
||||
headersOriginal: req.headers
|
||||
};
|
||||
const pageContext = await renderPage(pageContextInit);
|
||||
if (pageContext.errorWhileRendering) {
|
||||
// Install error tracking here, see https://vike.dev/error-tracking
|
||||
}
|
||||
const { httpResponse } = pageContext;
|
||||
if (res.writeEarlyHints)
|
||||
res.writeEarlyHints({ link: httpResponse.earlyHints.map((e) => e.earlyHintLink) });
|
||||
httpResponse.headers.forEach(([name, value]) => res.setHeader(name, value));
|
||||
res.status(httpResponse.statusCode);
|
||||
// For HTTP streams use pageContext.httpResponse.pipe() instead, see https://vike.dev/streaming
|
||||
res.send(httpResponse.body);
|
||||
});
|
||||
const host = process.env.HOST || config.web.host || 'localhost';
|
||||
const port = process.env.PORT || config.web.port || 3000;
|
||||
app.listen(port, host, () => {
|
||||
console.log(`Server running at http://${host}:${port}`);
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=server.js.map
|
||||
1
dist/web/server.js.map
vendored
Normal file
1
dist/web/server.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/web/server.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,UAAU,MAAM,SAAS,CAAC;AACjC,OAAO,WAAW,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,YAAY,GAAG,OAAO,CAAC,GA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