refactor: serve static files through next's server instead of system-api

This commit is contained in:
Nicolas Meienberger 2023-02-04 16:26:35 +01:00 committed by Nicolas Meienberger
parent 365f2fb1ab
commit c42b96ae53
5 changed files with 27 additions and 15 deletions

View file

@ -27,6 +27,7 @@
"@trpc/server": "^10.9.1",
"argon2": "^0.29.1",
"clsx": "^1.1.1",
"express": "^4.17.3",
"fs-extra": "^10.1.0",
"graphql": "^15.8.0",
"graphql-tag": "^2.12.6",
@ -63,6 +64,7 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^14.4.3",
"@types/express": "^4.17.13",
"@types/fs-extra": "^9.0.13",
"@types/isomorphic-fetch": "^0.0.36",
"@types/jest": "^29.2.4",

View file

@ -1,5 +1,5 @@
/* eslint-disable consistent-return */
import { createServer } from 'http';
import express from 'express';
import { parse } from 'url';
import next from 'next';
import { EventDispatcher } from './src/server/core/EventDispatcher';
@ -15,25 +15,32 @@ const nextApp = next({ dev });
const handle = nextApp.getRequestHandler();
nextApp.prepare().then(async () => {
createServer(async (req, res) => {
const app = express();
app.disable('x-powered-by');
app.use('/static', express.static(`${getConfig().rootFolder}/repos/${getConfig().appsRepoId}/`));
app.all('*', (req, res) => {
const parsedUrl = parse(req.url!, true);
handle(req, res, parsedUrl);
}).listen(port);
});
const appService = new AppServiceClass(prisma);
EventDispatcher.clear();
app.listen(port, async () => {
const appService = new AppServiceClass(prisma);
EventDispatcher.clear();
// Run database migrations
await runPostgresMigrations();
// Run database migrations
await runPostgresMigrations();
// startJobs();
setConfig('status', 'RUNNING');
// startJobs();
setConfig('status', 'RUNNING');
await EventDispatcher.dispatchEventAsync('clone_repo', [getConfig().appsRepoUrl]);
await EventDispatcher.dispatchEventAsync('update_repo', [getConfig().appsRepoUrl]);
await EventDispatcher.dispatchEventAsync('clone_repo', [getConfig().appsRepoUrl]);
await EventDispatcher.dispatchEventAsync('update_repo', [getConfig().appsRepoUrl]);
appService.startAllApps();
appService.startAllApps();
Logger.info(`> Server listening at http://localhost:${port} as ${dev ? 'development' : process.env.NODE_ENV}`);
Logger.info(`> Server listening at http://localhost:${port} as ${dev ? 'development' : process.env.NODE_ENV}`);
});
});

View file

@ -4,7 +4,7 @@ import { getUrl } from '../../core/helpers/url-helpers';
import styles from './AppLogo.module.scss';
export const AppLogo: React.FC<{ id?: string; size?: number; className?: string; alt?: string }> = ({ id, size = 80, className = '', alt = '' }) => {
const logoUrl = id ? `/api-legacy/apps/${id}/metadata/logo.jpg` : getUrl('placeholder.png');
const logoUrl = id ? `/static/apps/${id}/metadata/logo.jpg` : getUrl('placeholder.png');
return (
<div aria-label={alt} className={clsx(styles.dropShadow, className)} style={{ width: size, height: size }}>

View file

@ -24,7 +24,6 @@ const main = async () => {
const port = 3001;
app.use(cors(corsOptions));
app.use(express.static(`${getConfig().rootFolder}/repos/${getConfig().appsRepoId}`));
app.use(getSessionMiddleware);
const httpServer = createServer(app);

View file

@ -34,6 +34,7 @@ importers:
'@trpc/next': ^10.9.1
'@trpc/react-query': ^10.9.1
'@trpc/server': ^10.9.1
'@types/express': ^4.17.13
'@types/fs-extra': ^9.0.13
'@types/isomorphic-fetch': ^0.0.36
'@types/jest': ^29.2.4
@ -63,6 +64,7 @@ importers:
eslint-plugin-jsx-a11y: ^6.6.1
eslint-plugin-react: ^7.31.10
eslint-plugin-react-hooks: ^4.6.0
express: ^4.17.3
fs-extra: ^10.1.0
graphql: ^15.8.0
graphql-tag: ^2.12.6
@ -114,6 +116,7 @@ importers:
'@trpc/server': 10.9.1
argon2: 0.29.1
clsx: 1.1.1
express: 4.18.1
fs-extra: 10.1.0
graphql: 15.8.0
graphql-tag: 2.12.6_graphql@15.8.0
@ -149,6 +152,7 @@ importers:
'@testing-library/jest-dom': 5.16.5
'@testing-library/react': 13.4.0_biqbaboplfbrettd7655fr4n2y
'@testing-library/user-event': 14.4.3_aaq3sbffpfe3jnxzm2zngsddei
'@types/express': 4.17.13
'@types/fs-extra': 9.0.13
'@types/isomorphic-fetch': 0.0.36
'@types/jest': 29.2.4