Skip to content

Commit

Permalink
chore: upgrade alokai middleware to 5.3.2 (#933)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxiroellplenty authored Jan 7, 2025
1 parent b956fcd commit cdb23ad
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 174 deletions.
4 changes: 3 additions & 1 deletion apps/server/middleware.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import dotenv from 'dotenv';
import * as path from 'path';

dotenv.config({
path: path.resolve(__dirname, '../web/.env'),
});

const config = {
logger: {
verbosity: process.env.LOG_LEVEL ?? 'info',
},
integrations: {
plentysystems: {
location: '@plentymarkets/shop-api/server',
Expand Down
6 changes: 2 additions & 4 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
},
"dependencies": {
"@types/cors": "^2.8.17",
"@vue-storefront/middleware": "3.10.0",
"@vue-storefront/middleware": "5.3.2",
"consola": "^3.2.3",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.21.2"
"dotenv": "^16.4.5"
},
"devDependencies": {
"@types/express": "^5.0.0",
"eslint": "^8.57.0",
"eslint-plugin-prettier": "5.1.3",
"nodemon": "^3.1.4",
Expand Down
39 changes: 18 additions & 21 deletions apps/server/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { createServer } from '@vue-storefront/middleware';
import consola from 'consola';
import cors from 'cors';
import config from '../middleware.config';
import * as express from 'express';

const useIPV6 = process.env.USE_IPV6 === 'true';

Expand All @@ -19,29 +17,28 @@ const checkEnvironments = (integrations: any) => {
}
};

const setCorsMiddleware = (app: any) => {
const CORS_MIDDLEWARE_NAME = 'corsMiddleware';
const corsMiddleware = app._router.stack.find((middleware: any) => middleware.name === CORS_MIDDLEWARE_NAME);
corsMiddleware.handle = cors({
origin: ['http://localhost:3000', ...(process.env.MIDDLEWARE_ALLOWED_ORIGINS?.split(',') ?? [])],
credentials: true,
});
};

const setJsonMiddleware = (app: any) => {
const jsonMiddleware = app._router.stack.find((layer: any) => layer.name === 'jsonParser');
if (jsonMiddleware) {
jsonMiddleware.handle = express.json({ limit: '13.5mb' }); // 13,3mb for 10mb upload file
}
};

(async () => {
const app = await createServer({ integrations: config.integrations });
const app = await createServer(
{ integrations: config.integrations },
{
cors: {
origin: 'http://localhost:3000',
credentials: true,
},
bodyParser: {
limit: '50mb',
},
fileUpload: {
enabled: true,
maxFileSize: 14_155_776, // 13,3mb for 10mb upload file
maxFiles: 5,
},
},
);

const host = useIPV6 ? '::' : '0.0.0.0';
const port = Number(process.argv[3]) || 8181;

setCorsMiddleware(app);
setJsonMiddleware(app);
checkEnvironments(config.integrations);

app.listen(port, host, () => {
Expand Down
4 changes: 2 additions & 2 deletions apps/server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"strict": true,
"target": "ES2019",
"types": [
"@types/express",
"jest"
"jest",
"@vue-storefront/middleware",
],
"rootDir": ".",
"outDir": "lib"
Expand Down
1 change: 1 addition & 0 deletions apps/web/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ ENABLE_QUICK_CHECKOUT_TIMER=1
NEWSLETTERFORM=true
NEWSLETTERFORMNAMES=false
DEFAULT_FEEDBACK_ITEMS_PER_PAGE=10
LOG_LEVEL=info
2 changes: 1 addition & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@types/node": "^20.14.9",
"@vite-pwa/nuxt": "^0.10.6",
"@vitest/coverage-v8": "^0.33.0",
"@vue-storefront/middleware": "^3.10.0",
"@vue-storefront/middleware": "5.3.2",
"@vue-storefront/nuxt": "^3.1.1",
"@vue-storefront/unified-data-model": "^0.18.1",
"@vue/test-utils": "^2.4.6",
Expand Down
Loading

0 comments on commit cdb23ad

Please sign in to comment.