forked from mehtaAnsh/BlockChainVoting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
42 lines (33 loc) · 1.04 KB
/
server.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
const next = require('next');
const express = require('express');
const voter = require('./routes/voter');
const company = require('./routes/company');
const candidate = require('./routes/candidate');
const bodyParser = require('body-parser');
const mongoose = require('./config/database');
const exp = express();
const path = require('path');
require('dotenv').config({ path: __dirname + '/.env' });
mongoose.connection.on('error', console.error.bind(console, 'MongoDB connection error:'));
exp.use(
bodyParser.urlencoded({
extended: true,
})
);
exp.use(bodyParser.json());
exp.get('/', function (req, res) {
res.sendFile(path.join(__dirname + '/pages/homepage.js'));
});
exp.use('/company', company);
exp.use('/voter', voter);
exp.use('/candidate', candidate);
const app = next({
dev: process.env.NODE_ENV !== 'production',
});
const routes = require('./routes');
const handler = routes.getRequestHandler(app);
app.prepare().then(() => {
exp.use(handler).listen(3000, function () {
console.log('Node server listening on port 3000');
});
});