Skip to content

Commit

Permalink
Merge pull request #9 from AzureCosmosDB/auto-20241028131039
Browse files Browse the repository at this point in the history
[AUTO] 2024-10-28 | Merge latest from source repo
  • Loading branch information
2 parents be23b9c + e58d510 commit fa2e049
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions .webappignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
16 changes: 14 additions & 2 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,28 @@ 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'

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'));
});

Expand Down
6 changes: 3 additions & 3 deletions cosmos.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -23,7 +23,7 @@ export class DataClient {
emit('Current Status:\tFinalizing...');
}

async createClient(emit: Emit): Promise<CosmosClient> {
async createClient(_: Emit): Promise<CosmosClient> {
const client = new CosmosClient(
"<azure-cosmos-db-nosql-connection-string>"
);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@azure/identity": "^4",
"dotenv": "^16",
"express": "^4",
"express-rate-limit": "^7",
"serve-favicon": "^2",
"socket.io": "^4"
},
Expand Down
4 changes: 3 additions & 1 deletion static/socket.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
$(function () {
const socket = io();
const socket = io({
transports: ['websocket', 'polling']
});

socket.on('connect', function() {
console.log('Connected!');
Expand Down

0 comments on commit fa2e049

Please sign in to comment.