Skip to content

Commit

Permalink
Merge pull request #10 from tlsnotary/compression
Browse files Browse the repository at this point in the history
Compression + lint fixes
  • Loading branch information
Codetrauma authored Nov 11, 2024
2 parents a30f689 + e8fa9e0 commit 4ee279e
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 39 deletions.
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@
},
"repository": {
"type": "git",
"url": ""
"url": "https://github.com/tlsnotary/tlsn-plugin-demo"
},
"author": "",
"license": "ISC",
"bugs": {
"url": ""
},
"dependencies": {
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
Expand Down Expand Up @@ -74,6 +71,7 @@
"babel-loader": "^9.2.1",
"babel-preset-react-app": "^10.0.1",
"clean-webpack-plugin": "^4.0.0",
"compression-webpack-plugin": "^11.1.0",
"copy-webpack-plugin": "^12.0.2",
"css-loader": "^7.1.2",
"eslint": "8.1.0",
Expand Down Expand Up @@ -109,4 +107,4 @@
"webpack-dev-server": "^4.11.1"
},
"homepage": ""
}
}
56 changes: 26 additions & 30 deletions server/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { Mutex } from 'async-mutex';
//@ts-ignore
import { verify } from '../rs/0.1.0-alpha.7/index.node';
import { convertNotaryWsToHttp, fetchPublicKeyFromNotary } from './util/index';
import { localPem } from '../web/utils/constants';


const app = express();
const port = 3030;
Expand Down Expand Up @@ -42,35 +40,33 @@ const mutex = new Mutex();

app.get('*', (req, res) => {
try {


const storeConfig: AppRootState = {
attestation: {
raw: {
version: '0.1.0-alpha.7',
data: '',
meta: {
notaryUrl: '',
websocketProxyUrl: '',
pluginUrl: '',
const storeConfig: AppRootState = {
attestation: {
raw: {
version: '0.1.0-alpha.7',
data: '',
meta: {
notaryUrl: '',
websocketProxyUrl: '',
pluginUrl: '',
},
},
},
},
};
};

const store = configureAppStore(storeConfig);
const store = configureAppStore(storeConfig);

const html = renderToString(
<Provider store={store}>
<StaticRouter location={req.url}>
<App />
</StaticRouter>
</Provider>,
);
const html = renderToString(
<Provider store={store}>
<StaticRouter location={req.url}>
<App />
</StaticRouter>
</Provider>,
);

const preloadedState = store.getState();
const preloadedState = store.getState();

res.send(`
res.send(`
<!DOCTYPE html>
<html lang="en">
<head>
Expand All @@ -89,8 +85,8 @@ app.get('*', (req, res) => {
</body>
</html>
`);
} catch (e) {
res.send(`
} catch (e) {
res.send(`
<!DOCTYPE html>
<html lang="en">
<head>
Expand All @@ -109,7 +105,7 @@ app.get('*', (req, res) => {
</body>
</html>
`);
}
}
});

app.post('/poap-claim', async (req, res) => {
Expand Down Expand Up @@ -140,7 +136,7 @@ app.post('/verify-attestation', async (req, res) => {
try {
const notaryUrl = convertNotaryWsToHttp(attestation.meta.notaryUrl);
const notaryPem = await fetchPublicKeyFromNotary(notaryUrl);
console.log(notaryPem)
console.log('SERVER NOTARY PEM', notaryPem);
const presentation = await verify(attestation.data, notaryPem);

const presentationObj = {
Expand All @@ -150,7 +146,7 @@ app.post('/verify-attestation', async (req, res) => {
res.json({ presentationObj });
} catch (e) {
console.error(e);
res.status(500).send('Error verifying attestation')
res.status(500).send('Error verifying attestation');
}
});

Expand Down
3 changes: 2 additions & 1 deletion server/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export function convertNotaryWsToHttp(notaryWs: string) {
export async function fetchPublicKeyFromNotary(notaryUrl: string) {
try {
const url = new URL(notaryUrl);
const { hostname } = url;
const { hostname } = url;
console.log('HOSTNAME', hostname);
if (hostname === '127.0.0.1' || hostname === 'localhost') return localPem;
const res = await fetch(notaryUrl + '/info');
const json: any = await res.json();
Expand Down
2 changes: 1 addition & 1 deletion web/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const localPem = `-----BEGIN PUBLIC KEY-----MDYwEAYHKoZIzj0CAQYFK4EEAAoDIgADe0jxnBObaIj7Xjg6TXLCM1GG/VhY5650\nOrS/jgcbBuc=-----END PUBLIC KEY-----`;
export const localPem = "-----BEGIN PUBLIC KEY-----\nMDYwEAYHKoZIzj0CAQYFK4EEAAoDIgADe0jxnBObaIj7Xjg6TXLCM1GG/VhY5650\nOrS/jgcbBuc=\n-----END PUBLIC KEY-----\n";
10 changes: 8 additions & 2 deletions webpack.server.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var webpack = require('webpack'),
path = require('path'),
CompressionPlugin = require('compression-webpack-plugin'),
CopyWebpackPlugin = require('copy-webpack-plugin'),
HtmlWebpackPlugin = require('html-webpack-plugin'),
TerserPlugin = require('terser-webpack-plugin');
var { CleanWebpackPlugin } = require('clean-webpack-plugin');

Expand Down Expand Up @@ -88,9 +88,15 @@ const options = {
new CopyWebpackPlugin({
patterns: [
{ from: 'server/util/poaps.txt', to: 'util/' },
{ from: 'server/util/assignments.json', to: 'util/'}
{ from: 'server/util/assignments.json', to: 'util/' }
],
}),
new CompressionPlugin({
algorithm: 'gzip',
test: /\.(js|css|html|svg)$/,
threshold: 10240,
deleteOriginalAssets: false,
}),
].filter(Boolean),
infrastructureLogging: {
level: 'info',
Expand Down

0 comments on commit 4ee279e

Please sign in to comment.