Aplicação MEAN com Angular, TypeScript e Azure Cosmos DB
#AzureOpenDev
Java, JavaScript + HTML5, Sencha, Cordova/Ionic, Angular, RxJS + all things reactive
Angular
MEAN
Cosmos DB
Deploy
MEAN app
proxy.conf.json
{
"/api": {
"target": "http://localhost:3000",
"secure": false
},
"logLevel": "debug"
}
package.json
"scripts": {
"ng": "ng",
"start": "node src/server/index.js",
"start-ng": "ng serve --proxy-config proxy.conf.json",
"build": "ng build --prod"
}
@Controller('contacts')
export class ContactsController {
constructor(private readonly contactsService: ContactsService) {}
@Get()
async findAll(): Promise<Contact[]> {
return this.contactsService.findAll();
}
@Get(':id')
async getById(@Res() res: Response, @Param('id') id: string) {
const contact = await this.contactsService.findById(id);
res.status(HttpStatus.OK).json(contact);
}
@Post()
async create(@Body() contact: CreateContactDto): Promise<Contact> {
return this.contactsService.create(contact);
}
@Delete(':id')
public async delete(@Res() res: Response, @Param('id') id: string) {
const hero = await this.contactsService.remove(id);
if (hero) {
res.status(HttpStatus.NO_CONTENT).send();
} else {
throw new NotFoundException('');
}
}
}
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "documentDB",
"name": "contacts",
"databaseName": "admin",
"collectionName": "contacts",
"connection": "angular-cosmosdb-functions_DOCUMENTDB",
"direction": "out"
}
],
"disabled": false
}
function.json
module.exports = function(context, req, contacts) {
context.log('JavaScript HTTP trigger function.');
context.res = {
body: context.bindings.contacts
};
context.done();
};
index.js