Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix azure function #1236

Merged
merged 5 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"type": "module",
"scripts": {
"dev": "nuxi dev",
"dev:azure": "NITRO_PRESET=azure yarn build && NUXT_PUBLIC_ENVIRONMENT=development npx @azure/static-web-apps-cli start .output/public --api-location .output/server",
"build": "nuxi build --fail-on-error",
"build:azure": "NITRO_PRESET=azure yarn build",
"start": "nuxi preview",
"start:azure": "NUXT_PUBLIC_ENVIRONMENT=development npx @azure/static-web-apps-cli start .output/public --api-location .output/server",
"generate": "yarn prisma:generate && yarn graphql:generate",
"generate:watch": "concurrently \"yarn:*:generate:watch\"",
"prisma:migrate:dev": "prisma migrate dev",
Expand Down Expand Up @@ -82,6 +83,7 @@
"typescript": "^4.7.4"
},
"devDependencies": {
"@azure/static-web-apps-cli": "^1.0.2",
"@babel/core": "^7.18.6",
"@graphql-codegen/cli": "^2.8.1",
"@graphql-codegen/fragment-matcher": "^3.3.0",
Expand Down
15 changes: 15 additions & 0 deletions patches/redis-mock+0.56.3.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/node_modules/redis-mock/lib/server/redis-db.js b/node_modules/redis-mock/lib/server/redis-db.js
index 35583cc..2eea5df 100644
--- a/node_modules/redis-mock/lib/server/redis-db.js
+++ b/node_modules/redis-mock/lib/server/redis-db.js
@@ -28,7 +28,8 @@ class RedisDb {
*
* The server contains a log of logic. It only feels natural to split it into multiple files
*/
-['./strings', './keys', './hash', './set', './list.js', './sortedset']
- .forEach((lib) => Object.assign(RedisDb.prototype, require(lib)));
+// CHANGED: Don't need those, and they throw module not found errors
+//['./strings', './keys', './hash', './set', './list.js', './sortedset']
+// .forEach((lib) => Object.assign(RedisDb.prototype, require(lib)));

module.exports = RedisDb;
7 changes: 1 addition & 6 deletions plugins/apollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ export default defineNuxtPlugin((nuxtApp) => {
}

const config = useRuntimeConfig()
let httpLink
if (config.public.environment === Environment.LocalDevelopment) {
httpLink = new HttpLink({ uri: 'http://localhost:3000/api', fetch })
} else {
httpLink = new HttpLink({ uri: '/api', fetch })
}
const httpLink = new HttpLink({ uri: '/api', fetch })

// Print errors
const errorLink = onError((error) => {
Expand Down
31 changes: 31 additions & 0 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,37 @@ import { buildContext } from './context'
import { loadSchemaWithResolvers } from './schema'
import { resolve } from './tsyringe'

// Workaround for issue with Azure deploy: https://github.com/unjs/nitro/issues/351
// Original code taken from https://github.com/nodejs/node/blob/main/lib/_http_outgoing.js
http.OutgoingMessage.prototype.setHeader = function setHeader(name, value) {
// @ts-ignore: Is workaround anyway
if (this._header) {
// CHANGED: Don't throw an error in this case, as workaround for https://github.com/unjs/h3/issues/21
// throw new Error('Cannot set headers after they are sent to the client')
}
// CHANGED: No idea where to find these methods
// validateHeaderName(name)
// validateHeaderValue(name, value)

// CHANGED: Extra logic to find kOutHeaders symbol in `this`
const kOutHeaders = Object.getOwnPropertySymbols(this).find(
(sym) => sym.toString() === 'Symbol(kOutHeaders)'
)

// @ts-ignore: Is workaround anyway
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
let headers = this[kOutHeaders]
// CHANGED: === to == to cover undefined case
if (headers == null) {
// @ts-ignore: Is workaround anyway
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
this[kOutHeaders] = headers = Object.create(null)
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
headers[name.toLowerCase()] = [name, value]
return this
}

// Create express instance
const app = express()
if (useRuntimeConfig().public.environment === Environment.Production) {
Expand Down
Loading