Skip to content

Instantly share code, notes, and snippets.

@cleuton
Created May 9, 2014 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cleuton/ba1656cfe85f752384d2 to your computer and use it in GitHub Desktop.
Save cleuton/ba1656cfe85f752384d2 to your computer and use it in GitHub Desktop.
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