Skip to content

Commit

Permalink
Merge pull request #48 from ItzNotABug/sample-update
Browse files Browse the repository at this point in the history
Sample Update
  • Loading branch information
ItzNotABug authored Oct 5, 2024
2 parents 346ad4e + 6a115c2 commit 72c5286
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 36 deletions.
10 changes: 5 additions & 5 deletions function/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
"express-hbs": "2.5.0",
"@itznotabug/appexpress": "^1.6.2",
"@itznotabug/appexpress-jsx": "^0.0.4",
"@itznotabug/appexpress-cors": "^0.0.1",
"@itznotabug/appexpress-favicon": "^0.0.2",
"@itznotabug/appexpress-minifier": "^0.0.4",
"@itznotabug/appexpress-apicache": "^0.0.3",
"@itznotabug/appexpress-nocookies": "^0.0.3"
"@itznotabug/appexpress-cors": "^0.0.2",
"@itznotabug/appexpress-favicon": "^0.0.3",
"@itznotabug/appexpress-minifier": "^0.0.5",
"@itznotabug/appexpress-apicache": "^0.0.5",
"@itznotabug/appexpress-nocookies": "^0.0.4"
},
"devDependencies": {
"prettier": "3.2.5",
Expand Down
49 changes: 18 additions & 31 deletions function/utils/middlewares.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import cors from '@itznotabug/appexpress-cors';
import favIcon from '@itznotabug/appexpress-favicon';
import apiCache from '@itznotabug/appexpress-apicache';
import minifier from '@itznotabug/appexpress-minifier';
import * as cache from '@itznotabug/appexpress-apicache';
import noCookies from '@itznotabug/appexpress-nocookies';
import { authUserForConsoleMiddleware } from '../middlewares/auth.js';

export default (express) => {
logEverything(express);
cacheEverything(express);
favIconMiddleware(express);
minifierMiddleware(express);
express.middleware(cors.middleware);
express.middleware(noCookies.middleware);
express.middleware(cors());
express.middleware(noCookies());
express.middleware(authUserForConsoleMiddleware);
express.middleware(cache.createApiCache({ timeout: 0 }));
express.middleware(favIcon({ iconPath: 'icons/favicon.ico' }));
};

const logEverything = (express) => {
Expand All @@ -21,36 +21,23 @@ const logEverything = (express) => {

// these won't be marked unsupported!
console.log(`Requested Path: ${url}`);
if (apiCache.hasCache(url)) {
if (cache.hasCache(url)) {
console.log(`This url (${url}) is cached!`);
}
});
};

const cacheEverything = (express) => {
apiCache.options({ timeout: 0 });
express.middleware(apiCache.middleware);
};

const favIconMiddleware = (express) => {
favIcon.options({
iconPath: 'icons/favicon.ico',
});

express.middleware(favIcon.middleware);
};

const minifierMiddleware = (express) => {
minifier.options({
excludes: ['/robots.txt'],
htmlOptions: {
minifyJS: true,
minifyCSS: true,
removeComments: true,
collapseWhitespace: true,
preserveLineBreaks: false,
},
});

express.middleware(minifier.middleware);
express.middleware(
minifier({
excludes: ['/robots.txt'],
htmlOptions: {
minifyJS: true,
minifyCSS: true,
removeComments: true,
collapseWhitespace: true,
preserveLineBreaks: false,
},
}),
);
};

0 comments on commit 72c5286

Please sign in to comment.