Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Demo async app
/*
Copyright 2014 Cleuton Sampaio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* Module dependencies.
*/
var express = require('express');
var routes = require('./routes');
var http = require('http');
var path = require('path');
var app = express();
// all environments
app.set('port', process.env.PORT || 8080);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
// Página default:
app.get('/', routes.index);
// Iniciar operação assíncrona. Retorna um UUID:
app.get('/operacao', routes.iniciar);
// Rota para saber se já terminou a operação assíncrona:
app.get('/operacao/:chave', routes.verify);
http.createServer(app).listen(app.get('port'), function(){
console.log('Aguardando conexão... ' + app.get('port'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment