mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-04-29 02:42:47 -04:00
* `sd_init.json` support * bruh * Add `sd_init.json` to developer docs * Ran cargo clippy --fix to fix warnings * Dafuq, cargo clippy --fix messed up cargo fmt --------- Co-authored-by: Ericson Soares <ericson.ds999@gmail.com>
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import compression from 'compression';
|
|
import express from 'express';
|
|
import { renderPage } from 'vite-plugin-ssr';
|
|
|
|
const isProduction = process.env.NODE_ENV === 'production';
|
|
const root = `${__dirname}/..`;
|
|
|
|
startServer();
|
|
|
|
async function startServer() {
|
|
const app = express();
|
|
|
|
app.use(compression());
|
|
|
|
if (isProduction) {
|
|
const sirv = require('sirv');
|
|
app.use(sirv(`${root}/dist/client`));
|
|
} else {
|
|
const vite = require('vite');
|
|
const viteDevMiddleware = (
|
|
await vite.createServer({
|
|
root,
|
|
server: { middlewareMode: true }
|
|
})
|
|
).middlewares;
|
|
app.use(viteDevMiddleware);
|
|
}
|
|
|
|
app.get('*', async (req, res, next) => {
|
|
const url = req.originalUrl;
|
|
const pageContextInit = {
|
|
urlOriginal: url
|
|
};
|
|
const pageContext = await renderPage(pageContextInit);
|
|
const { httpResponse } = pageContext;
|
|
if (!httpResponse) return next();
|
|
const { body, statusCode, contentType } = httpResponse;
|
|
res.status(statusCode).type(contentType).send(body);
|
|
});
|
|
|
|
const port = process.env.PORT || 3000;
|
|
// @ts-ignore: I don't get why this isn't valid they have a definition matching this.
|
|
app.listen(port, '0.0.0.0');
|
|
console.log(`Server running at http://localhost:${port}`);
|
|
}
|