generated from net-square-designs/Errnd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
69 lines (58 loc) · 1.62 KB
/
index.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
/* eslint-disable import/no-cycle */
/* eslint-disable no-console */
// Packages
import express from 'express';
import morgan from 'morgan';
import bodyParser from 'body-parser';
import validator from 'express-validator';
import passport from 'passport';
import cors from 'cors';
import passportConfig from './config/passport/facebook';
import { StatusResponse } from './helpers';
// Routes
import {
auth,
profile,
products,
roles
} from './routes';
const PORT = process.env.PORT || 3006;
const app = express();
app.use(cors());
app.use(morgan('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(validator());
app.use(passport.initialize());
app.use(passport.session());
app.use('/api/v1/auth', auth);
app.use('/api/v1/profile', profile);
app.use('/api/v1/products', products);
app.use('/api/v1/roles', roles);
passportConfig();
// Default to here on home route
app.get('/', (req, res) => StatusResponse.success(res, {
status: 200,
data: {
message: 'Welcome to AdvertiseIt API, A platform to do social commerce'
}
}));
// Default to here on api/v1 route
app.get('/api/v1', (req, res) => StatusResponse.success(res, {
status: 200,
data: {
message: 'Welcome to AdvertiseIt API, A platform to do social commerce'
}
}));
// Default to here on routes not yet available
app.use('/*', (req, res) => StatusResponse.notfound(res, {
status: 404,
data: {
error: 'Endpoint does not exist ... yet'
}
}));
export const server = app.listen(PORT, () => {
console.log(`API live on port =>: ${PORT}`);
});
export const environment = process.env.NODE_ENV;
export default app;