Skip to content

Commit 1900713

Browse files
committed
app up and running!
1 parent 705fc7e commit 1900713

14 files changed

+242
-27
lines changed

.funcignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.js.map
2+
*.ts
3+
.git*
4+
.vscode
5+
local.settings.json
6+
test
7+
tsconfig.json

host.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": "2.0",
3+
"extensionBundle": {
4+
"id": "Microsoft.Azure.Functions.ExtensionBundle",
5+
"version": "[1.*, 2.0.0)"
6+
},
7+
"extensions": {
8+
"http": {
9+
"routePrefix": "api"
10+
}
11+
}
12+
}

local.settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"IsEncrypted": false,
3+
"Values": {
4+
"AzureWebJobsStorage": "",
5+
"FUNCTIONS_WORKER_RUNTIME": "node"
6+
}
7+
}

main/function.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"bindings": [
3+
{
4+
"authLevel": "anonymous",
5+
"type": "httpTrigger",
6+
"direction": "in",
7+
"name": "req",
8+
"route": "{*segments}"
9+
},
10+
{
11+
"type": "http",
12+
"direction": "out",
13+
"name": "res"
14+
}
15+
],
16+
"scriptFile": "../dist/main/index.js"
17+
}

main/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Context, HttpRequest } from "@azure/functions";
2+
import { AzureHttpAdapter } from "@nestjs/azure-func-http";
3+
import { createApp } from "../src/main.azure";
4+
5+
export default function(context: Context, req: HttpRequest): void {
6+
context.res = {
7+
headers: {
8+
"Content-Type": "application/json"
9+
}
10+
};
11+
AzureHttpAdapter.handle(createApp, context, req);
12+
}

main/sample.dat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "Azure"
3+
}

package-lock.json

Lines changed: 126 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
{
2-
"name": "nest-typescript-starter",
2+
"name": "nestjs-graphql-azure-functions",
33
"version": "1.0.0",
4-
"description": "Nest TypeScript starter repository",
4+
"description": "Sample nestjs app with graphql deployed to an azure function app",
5+
"author": "Andrew Moss",
56
"license": "MIT",
7+
"repository": {
8+
"type": "git",
9+
"url": "https://github.com/agmoss/nestjs-graphql-azure-functions.git"
10+
},
11+
"keywords": [
12+
"nestjs",
13+
"graphql",
14+
"azure-functions",
15+
"serverless"
16+
],
617
"scripts": {
718
"prebuild": "rimraf dist",
8-
"build": "nest build",
19+
"build": "rimraf dist && tsc -p tsconfig.build.json",
920
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
1021
"start": "nest start",
1122
"start:dev": "nest start --watch",
@@ -16,9 +27,12 @@
1627
"test:watch": "jest --watch",
1728
"test:cov": "jest --coverage",
1829
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
19-
"test:e2e": "echo 'No e2e tests implemented yet.'"
30+
"test:e2e": "echo 'No e2e tests implemented yet.'",
31+
"start:azure": "npm run build && func host start"
2032
},
2133
"dependencies": {
34+
"@azure/functions": "^1.0.3",
35+
"@nestjs/azure-func-http": "^0.4.2",
2236
"@nestjs/common": "6.11.8",
2337
"@nestjs/core": "6.11.8",
2438
"@nestjs/graphql": "6.5.5",

proxies.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "http://json.schemastore.org/proxies",
3+
"proxies": {}
4+
}

src/app.module.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
import { Module } from '@nestjs/common';
2-
import { GraphQLModule } from '@nestjs/graphql';
3-
import { RecipesModule } from './recipes/recipes.module';
1+
import { Module } from "@nestjs/common";
2+
import { GraphQLModule } from "@nestjs/graphql";
3+
import { RecipesModule } from "./recipes/recipes.module";
44

55
@Module({
66
imports: [
77
RecipesModule,
88
GraphQLModule.forRoot({
99
installSubscriptionHandlers: true,
10-
autoSchemaFile: 'schema.gql',
11-
}),
12-
],
10+
context: ({ req }) => ({ req }),
11+
autoSchemaFile: "schema.gql",
12+
useGlobalPrefix: true
13+
})
14+
]
1315
})
1416
export class AppModule {}

src/main.azure.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { INestApplication, ValidationPipe } from "@nestjs/common";
2+
import { NestFactory } from "@nestjs/core";
3+
import { AppModule } from "./app.module";
4+
5+
export async function createApp(): Promise<INestApplication> {
6+
const app = await NestFactory.create(AppModule);
7+
app.useGlobalPipes(new ValidationPipe());
8+
app.enableCors();
9+
app.setGlobalPrefix("api");
10+
await app.init();
11+
return app;
12+
}

src/main.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { ValidationPipe } from '@nestjs/common';
2-
import { NestFactory } from '@nestjs/core';
3-
import { AppModule } from './app.module';
1+
import { ValidationPipe } from "@nestjs/common";
2+
import { NestFactory } from "@nestjs/core";
3+
import { AppModule } from "./app.module";
44

55
async function bootstrap() {
66
const app = await NestFactory.create(AppModule);
77
app.useGlobalPipes(new ValidationPipe());
8+
app.enableCors();
9+
app.setGlobalPrefix("api");
810
await app.listen(3000);
911
}
1012
bootstrap();

0 commit comments

Comments
 (0)