Skip to content

Commit

Permalink
feat: add cors proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
mildronize committed May 1, 2024
1 parent eb24cf0 commit 570d605
Show file tree
Hide file tree
Showing 19 changed files with 4,696 additions and 5 deletions.
4 changes: 3 additions & 1 deletion background-job/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,6 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
.azurite
.azurite

local.settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "node",
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
"AzureWebJobsStorage": "UseDevelopmentStorage=true"
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"AzureSignalRConnectionString": "Endpoint=https://<your-service>.service.signalr.net;AccessKey"
},
"ConnectionStrings": {},
"watchDirectories": ["node_modules", "dist"]
Expand Down
2 changes: 1 addition & 1 deletion background-job/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ app.addFunctions(
cacheFunction,
resetCache,
negotiateSignalr,
func.httpGet('test').handler(c => c.text('Hello World'))
func.httpGet('test').handler(c => c.text('Hello World'+ ' ' ))
);

const dev = process.env.NODE_ENV === 'development';
Expand Down
2 changes: 1 addition & 1 deletion budget-app/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ AZURE_STORAGE_CONNECTION_STRING=UseDevelopmentStorage=true
AZURE_STORAGE_QUEUE_NAME=devqueue

AZURE_FUNCTION_RESET_CACHE_PATH=/api/resetcache
AZURE_FUNCTION_URL=http://localhost:7071
NEXT_PUBLIC_AZURE_FUNCTION_URL=http://localhost:7072
2 changes: 1 addition & 1 deletion budget-app/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const envSchema = z.object({
/**
* Azure Function URL
*/
NEXT_PUBLIC_AZURE_FUNCTION_URL: z.string().default("http://localhost:7071"),
NEXT_PUBLIC_AZURE_FUNCTION_URL: z.string().default("http://localhost:7072"),
});

function printSecretFields(
Expand Down
1 change: 1 addition & 0 deletions budget-app/src/libs/signalr-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as signalR from "@microsoft/signalr";

export async function initSignalRClient() {
const apiBaseUrl = env.NEXT_PUBLIC_AZURE_FUNCTION_URL;
console.log(`Connectioning to ${apiBaseUrl}`)
const connection = new signalR.HubConnectionBuilder()
.withUrl(new URL("/api", apiBaseUrl).toString())
.configureLogging(signalR.LogLevel.Information)
Expand Down
1 change: 1 addition & 0 deletions cors-reverse-proxy/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TARGET_URL=http://localhost:7071
11 changes: 11 additions & 0 deletions cors-reverse-proxy/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-env node */
module.exports = {
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
root: true,
ignorePatterns: ["**.test.ts"],
rules: {
'@typescript-eslint/consistent-type-imports': 'error',
}
};
130 changes: 130 additions & 0 deletions cors-reverse-proxy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
9 changes: 9 additions & 0 deletions cors-reverse-proxy/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"printWidth": 120,
"arrowParens": "avoid"
}
3 changes: 3 additions & 0 deletions cors-reverse-proxy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# CORS Reverse Proxy

Somehow Azure Functions host locally cannot setup CORS, here is temporary solution
Loading

0 comments on commit 570d605

Please sign in to comment.