-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
89 lines (71 loc) · 6.68 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
var privateKey = '-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEAshDMiFiIRzVRZgzdGJIDxUe+neRNRtGLeSBK1d/OuTpGbzmL\nH4FBMK3lhDAo/L+kZ2VmAzSwGZRZC4jTpapyABdof8tld4Ft48wsFWWjMlbtD9pV\nf2ERRgA4GIjYWMVuXlbtVuPHJs+/Bv/9klQrssLfVgGJE4HawlckbI/J+KC/SIZp\ng3hJZFOMrcSdLDuMWHm6w4q853go10Bhvb3Soga6MGfxO6fV/xVivvXaqHL4ixoU\ncBmQBbjtobJLeR+h0fa0nEkhTRN+Evc/3LXJ9t7rQ5z8tFgO3KeVFG0d6aESzhuP\nECbTW0ZPgt8ztcVu6Xe9Ye8886o0pWUkaUuI9wIDAQABAoIBAQCiKbJbKWVSlDgB\nHA3uZmuQqnnqCRRnPkYqlUIR7LSy82NZv6n3kxrvXi77Z3CsXUs37pwspzsI0JUX\ncBBvev4/HxJH79AEOZb+Md6jzeAF5CwYl9ntG1VDzsdHcLi2f3a366pRyzZ/Hgr2\nMQOY05bIQbhq9xMC9OtouTuusnRZO2VeXOtmmkD0j360v0wZCofIk1yRcSA8o28+\nN39zKIPn2eZWTkDGAFlb1lxPmpNNOsFS2nLtcYjnwKwp/zE4Wav963afaWc8/T1w\nMC0/X0ooCF8kZPrGiL5YvyZZev/ZinwvVRG9rUxdZ5SO4qcXidc54vLbOlVpIHws\nmnijaQthAoGBAOcZ3m8CKJ8aGIdB9VfweeNOTatvuZmVN+Qsq8nnicuFqUxcZQsF\nFKt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EBALIQ\nzIhYiEc1UWYM3RiSA8VHvp3kTUbRi3kgStXfzrk6Rm85ix+BQTCt5YQwKPy/pGdl\nZgM0sBmUWQuI06WqcgAXaH/LZXeBbePMLBVlozJW7Q/aVX9hEUYAOBiI2FjFbl5W\n7VbjxybPvwb//ZJUK7LC31YBiROB2sJXJGyPyfigv0iGaYN4SWRTjK3EnSw7jFh5\nusOKvOd4KNdAYb290qIGujBn8Tun1f8VYr712qhy+IsaFHAZkAW47aGyS3kfodH2\ntJxJIU0TfhL3P9y1yfbe60Oc/LRYDtynlRRtHemhEs4bjxAm01tGT4LfM7XFbul3\nvWHvPPOqNKVlJGlLiPcCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAJlhJMDvD5dBN\nu3neAUIJTpA8vbvYkpeZWNvderXKe6sLGp0KfFMtSdMW9KBaaWBItlMRlxMIvYyg\nCa32b9KCbzCziwVTg+RWckym1mLMioFoUgcZBSPPvN3DdXEnE/rUH34XZvca0Yqz\njsYtPa4carl1R9HsSc1bjpqhxlTWkw32G39lcszQHgI6ILrPBpLmVCgRkyRGpRcK\n7SQDpIblXeG55LWRO+P7h4LtuwkcMlzWEI7z15e4PWD52yC+P2tbcbravHyqSjHv\nSaJOUAeklsgRq3N62JtHoZajSkR3v9W2ENB42GjvLSf07em3fAhHtAnyZCMJvcvm\nqYC7qo905A==\n-----END CERTIFICATE-----';
var certificateAuthority = '-----BEGIN CERTIFICATE-----\nMIICpDCCAYwCCQDXvVZZzXgjEDANBgkqhkiG9w0BAQsFADAUMRIwEAYDVQQDDAls\nb2NhbGhvc3QwHhcNMTgxMTEyMTUzOTEzWhcNMTkxMTEyMTUzOTEzWjAUMRIwEAYD\nVQQDDAlsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC8\nngD6UyL3cgbStWKdtw1VVelkrQayu+MIqo3biOkTdYSHS1l/OBbkjEJW/yOBWLSU\n3+oEuHwfVxL879U2LogjnBHWx5oCRtCdyD4cgHanRhDlrYuQNj48wnZt/P1AzocI\ncuZmu7zboC3Ef7sOAo5IraOCp4FlCpobuHO47lmaC0vu8hkiTzaeewlFSMenZ4np\nyz33X1Oa4wnR21wss+RVDg9RsJv8FJp8U+jyFvdCANE86B2CY0whFKHyVWNrlBS5\n2ySURuSBPE34DhtHs4fmEpoFWYjBtXrGJXb3CU6eAQZX4WncSakiGJ7bIpocqBkg\nIdBkD2Fe+PkK6GbeAfG1AgMBAAEwDQYJKoZIhvcNAQELBQADggEBAHbJ4NEMWgBq\nv9ZCtGoz9teZ34Qfu5PXlstCjjUFAnUFQvXLrwwPgqeV7yqVSfSrr3JOdIUrPBGk\nqLO0MJjY40WB8GBHOB0J3N0nm5/iLFhCv5LoxzC18dTZpMaGk7etqIkVGz/bkYSO\n8puH+WRtekWmuLwnwBIq8bJereZOFU87p5qiU5WqUN3KSmnSvoHTbCSuHvEfmTZw\nBvA8bOE4jldqlk2sTSPyAauliefsSD9eybXPYE3TBf5U1FhML9h7GciPeOEpcpDg\niMdkG1XT3CZCi2uSzuQHJNfex8Mu0tCgwdVh2M8O7ZOsoxgFIktnQSN3JdScw+Nf\nO63QxGOPcQc=\n-----END CERTIFICATE-----';
// set up ======================================================================
// get all the tools we need
var express = require('express');
var app = express();
var port = process.env.PORT || 3009;
var mongoose = require('mongoose');
var flash = require('connect-flash');
var morgan = require('morgan');
var cookieParser = require('cookie-parser');
var session = require('express-session');
var time = require('time')(Date);
var sslConfig = require('ssl-config')('modern');
const createCert = require('create-cert');
var https = require('https');
// variables containing the routes files
var userRouter = require('./routes/users');
var ocorrenciasRouter = require('./routes/ocorrencias');
var dadosGeraisRouter = require('./routes/dados_gerais');
var enderecoRouter = require('./routes/endereco');
var responsavelLocalRouter = require('./routes/responsavel_local');
var sobreLocalRouter = require('./routes/sobre_local');
var sobreFatoRouter = require('./routes/sobre_fato');
var vestigiosRouter = require('./routes/vestigios');
var policiaisAcionadosRouter = require('./routes/policiais_acionados');
var obterListasRouter = require('./routes/obter_listas');
var testemunhasRouter = require('./routes/testemunhas');
// configuration ===============================================================
//mongoose.connect(process.env.MONGODB_URI || 'mongodb://localhost/policia_federal'); // connect to our database;
mongoose.connect(process.env.MONGODB_URI || 'mongodb://pfdb/policia_federal'); // connect to our database
// set up our express application
app.use(morgan('dev')); // log every request to the console
app.use(cookieParser()); // read cookies (needed for auth)
app.use(express.json()); // these two get information from html forms
app.use(express.urlencoded({ extended: true }));
// routes ======================================================================
app.use('/', userRouter);
app.use('/ocorrencias', ocorrenciasRouter);
app.use('/dados_gerais', dadosGeraisRouter);
app.use('/endereco', enderecoRouter);
app.use('/responsavel_local', responsavelLocalRouter);
app.use('/sobre_local', sobreLocalRouter);
app.use('/sobre_fato', sobreFatoRouter);
app.use('/vestigios', vestigiosRouter);
app.use('/policiais_acionados', policiaisAcionadosRouter);
app.use('/obter_listas', obterListasRouter);
app.use('/testemunhas', testemunhasRouter);
// launch ======================================================================
//Verificamos se as tebelas ja existem, caso nao, populamos o banco
mongoose.model('Estado').find().exec(function(err,results){
//Se nao achar os dados
if(results.length == 0){
//Popula banco
const popBanco = require('./routes/popular_banco');
var popularBanco = new popBanco();
popularBanco.popularBanco();
}
});
// SSL
var server = https.createServer({
key: privateKey,
cert: certificate,
ca: certificateAuthority,
ciphers: sslConfig.ciphers,
honorCipherOrder: true,
secureOptions: sslConfig.minimumTLSVersion
}, app);
server.listen(port)
console.log('Acesse localhost:' + port);