diff --git a/.webappignore b/.webappignore new file mode 100644 index 0000000..2eea525 --- /dev/null +++ b/.webappignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/app.ts b/app.ts index 796e463..a052041 100644 --- a/app.ts +++ b/app.ts @@ -3,6 +3,7 @@ import { createServer } from 'node:http'; import { join } from 'node:path'; import { Server } from 'socket.io'; import favicon from 'serve-favicon'; +import rateLimit, { RateLimitRequestHandler } from 'express-rate-limit'; import { DataClient } from './cosmos' @@ -10,9 +11,20 @@ import 'dotenv/config' const app: Application = express(); const server = createServer(app); -const io = new Server(server); +const io = new Server(server, { + transports: ['websocket', 'polling'], + cors: { + origin: '*', + methods: ['GET', 'POST'] + }, +}); + +const limiter: RateLimitRequestHandler = rateLimit({ + windowMs: 15 * 60 * 1000, // 15 minutes + max: 100, // limit each IP to 100 requests per windowMs +}); -app.get('/', (_: Request, res: Response) => { +app.get('/', limiter, (_: Request, res: Response) => { res.sendFile(join(__dirname, 'static', 'index.html')); }); diff --git a/cosmos.ts b/cosmos.ts index 32f60d4..2fab1b3 100644 --- a/cosmos.ts +++ b/cosmos.ts @@ -1,5 +1,5 @@ -import { DefaultAzureCredential } from '@azure/identity'; -import { Container, CosmosClient, Database, FeedResponse, ItemResponse, Resource, SqlQuerySpec } from '@azure/cosmos'; +import { DefaultAzureCredential, TokenCredential } from '@azure/identity'; +import { Container, CosmosClient, Database, FeedResponse, ItemResponse, SqlQuerySpec } from '@azure/cosmos'; import { Emit, Product } from './types' @@ -23,7 +23,7 @@ export class DataClient { emit('Current Status:\tFinalizing...'); } - async createClient(emit: Emit): Promise { + async createClient(_: Emit): Promise { const client = new CosmosClient( "" ); diff --git a/package.json b/package.json index 647987c..351384b 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "@azure/identity": "^4", "dotenv": "^16", "express": "^4", + "express-rate-limit": "^7", "serve-favicon": "^2", "socket.io": "^4" }, diff --git a/static/socket.js b/static/socket.js index 22e4b12..945d24d 100644 --- a/static/socket.js +++ b/static/socket.js @@ -1,5 +1,7 @@ $(function () { - const socket = io(); + const socket = io({ + transports: ['websocket', 'polling'] + }); socket.on('connect', function() { console.log('Connected!');