-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
37 lines (28 loc) · 1.03 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
const express = require('express');
const app = express();
const cors = require('cors')
const corsOptions = {
origin: 'http://localhost:4200',
optionsSuccessStatus: 200
};
app.use(cors(corsOptions));
const db = require('./src/config/db.config.js');
global.__basedir = __dirname;
// Resets and clears the database when the application is started
if ('mock' !== db.sequelize.options.dialect) {
db.sequelize.sync({force: true}).then(() => {
console.log('\n', '\n', '#### Resetting database and clearing all data. Ready to accept requests! ####', '\n', '\n');
});
}
// Router connections
let imageRouter = require('./src/routers/image.router.js');
let userRouter = require('./src/routers/user.router.js');
app.use('/', imageRouter);
app.use('/', userRouter);
// Starting the server itself
const server = app.listen(8080, function () {
let host = server.address().address
let port = server.address().port
console.log('\n', '\n', 'App listening at http://' + host + ':' + port, '\n', '\n');
});
module.exports = server;