<commit_before>/* global require, __dirname, console */
'use strict';

var express = require('express'),
    bodyParser = require('body-parser'),
    errorhandler = require('errorhandler'),
    morgan = require('morgan'),
    fs = require('fs'),
    https = require('https');


var nuve = require('../../src/client/nuve/nodejs').create({
    service: '__auto_generated_service_id__',
    key: '__auto_generated_service_key__',
    url: 'http://localhost:3000/'
});

var myRoomId;

nuve.getRooms(function(roomlist) {
    var rooms = JSON.parse(roomlist);
    console.log(rooms.length); //check and see if one of these rooms is 'basicExampleRoom'
    for (var room in rooms) {
        if (rooms[room].name === 'basicExampleRoom'){
            myRoomId = rooms[room]._id;
            break;
        }
    }
    if (!myRoomId) {
        nuve.createRoom({name: 'basicExampleRoom'}, function(roomID) {
            myRoomId = roomID._id;
            console.log('Created room ', myRoomId);
        });
    } else {
        console.log('Using room', myRoomId);
    }
});

var app = express();

// app.configure ya no existe
app.use(errorhandler({
    dumpExceptions: true,
    showStack: true
}));
app.use(morgan('dev'));
app.use(express.static(__dirname + '/public'));

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
    extended: true
}));

app.use(function(req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, DELETE');
    res.header('Access-Control-Allow-Headers', 'origin, content-type');
    if (req.method == 'OPTIONS') {
        res.send(200);
    } else {
        next();
    }
});

app.get('/getRooms/', function(req, res) {
    nuve.getRooms(function(rooms) {
        res.send(rooms);
    });
});

app.get('/getUsers/:room', function(req, res) {
    var room = req.params.room;
    nuve.getUsers(room, function(users) {
        res.send(users);
    });
});


app.post('/createToken/', function(req, res) {
    var room = myRoomId,
        username = req.body.username,
        role = req.body.role;
    nuve.createToken(room, username, role, function(token) {
        console.log(token);
        res.send(token);
    });
});


app.listen(3001);
https.createServer({
    key: fs.readFileSync('cert/key.pem').toString(),
    cert: fs.readFileSync('cert/cert.pem').toString()
}, app).listen(3004);
<commit_msg>Fixes basic_example: cert path<commit_after>/* global require, __dirname, console */
'use strict';

var express = require('express'),
    bodyParser = require('body-parser'),
    errorhandler = require('errorhandler'),
    morgan = require('morgan'),
    fs = require('fs'),
    path = require('path'),
    https = require('https');


var nuve = require('../../src/client/nuve/nodejs').create({
    service: '__auto_generated_service_id__',
    key: '__auto_generated_service_key__',
    url: 'http://localhost:3000/'
});

var myRoomId;

nuve.getRooms(function(roomlist) {
    var rooms = JSON.parse(roomlist);
    console.log(rooms.length); //check and see if one of these rooms is 'basicExampleRoom'
    for (var room in rooms) {
        if (rooms[room].name === 'basicExampleRoom'){
            myRoomId = rooms[room]._id;
            break;
        }
    }
    if (!myRoomId) {
        nuve.createRoom({name: 'basicExampleRoom'}, function(room) {
            myRoomId = JSON.parse(room)._id;
            console.log('Created room ', myRoomId);
        });
    } else {
        console.log('Using room', myRoomId);
    }
});

var app = express();

// app.configure ya no existe
app.use(errorhandler({
    dumpExceptions: true,
    showStack: true
}));
app.use(morgan('dev'));
app.use(express.static(__dirname + '/public'));

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
    extended: true
}));

app.use(function(req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, DELETE');
    res.header('Access-Control-Allow-Headers', 'origin, content-type');
    if (req.method == 'OPTIONS') {
        res.send(200);
    } else {
        next();
    }
});

app.get('/getRooms/', function(req, res) {
    nuve.getRooms(function(rooms) {
        res.send(rooms);
    });
});

app.get('/getUsers/:room', function(req, res) {
    var room = req.params.room;
    nuve.getUsers(room, function(users) {
        res.send(users);
    });
});


app.post('/createToken/', function(req, res) {
    var room = myRoomId,
        username = req.body.username,
        role = req.body.role;
    nuve.createToken(room, username, role, function(token) {
        console.log(token);
        res.send(token);
    });
});


app.listen(3001);
https.createServer({
    key: fs.readFileSync(path.resolve(__dirname, 'cert/key.pem')).toString(),
    cert: fs.readFileSync(path.resolve(__dirname, 'cert/cert.pem')).toString()
}, app).listen(3004);

{'fraction_non_alphanumeric': 0.17841902052428368, 'fraction_numerical': 0.00609632188579557, 'mean_word_length': 3.1016666666666666, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6930480', 'n_tokens_mistral': 1637, 'n_tokens_neox': 1612, 'n_words': 297}