-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
104 lines (69 loc) · 2.07 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
Notlar
1-Bu uygulama kapalı olunca, siteden kayıt olmaya çalışınca "bu üye mevcut" gibi yanlış uyarı geliyor.
*/
require("dotenv").config();
const express = require('express');
const corsMiddleware=require('./api/cors');
const swaggerJsDoc=require('swagger-jsdoc');
const swaggerUi=require('swagger-ui-express');
// https://swagger.io/specification/
const swaggerOptions=
{swaggerDefinition:{
info:{
title: "E-Commerce API",
description: "Ecommerce API - expressjs",
version: "1.0.0", // version number
contact: {
name: "Sawacrow",
email:"[email protected]"
},
servers:[
{
url:"http://localhost"
}
],
license: {
name: "Apache 2.0",
url: "https://www.apache.org/licenses/LICENSE-2.0.html"
},
version: "1.0.1"
}},
// [.routes./*.js]
apis:["./api/routes/*.js"]
}
const swaggerDocs=swaggerJsDoc(swaggerOptions);
const app = express();
app.use(corsMiddleware);
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
const productRoutes = require('./api/routes/products');
const categoriesRoutes = require('./api/routes/categories');
const usersRoutes = require('./api/routes/users');
const fileUpload = require('./api/routes/fileupload');
const logger = require('./api/config/logger');
app.use(express.static("public"))
/* test */
app.get('/', (req, res) => {
res.format({
'text/plain': function () {
res.send('hey')
},
'text/html': function () {
res.send('<p>hey html</p>')
},
'application/json': function () {
res.send({ message: 'hey' })
},
default: function () {
// log the request and respond with 406
res.status(406).send('Not Acceptable')
}
})
})
app.use('/products', productRoutes);
app.use('/categories', categoriesRoutes);
app.use('/users',usersRoutes);
app.use('/fileUpload',fileUpload);
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocs));
module.exports = app;