-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
54 lines (48 loc) · 1.27 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
import express from 'express';
import bodyParser from 'body-parser';
import userRoutes from './server/routers/userRoutes.js';
import postsRoutes from './server/routers/postsRouter.js';
import path from 'path';
import session from 'express-session';
import cors from 'cors';
import { fileURLToPath } from 'url';
import helmet from 'helmet';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = express();
const port = 3000;
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use('/uploads', express.static(path.join(__dirname, 'server', 'uploads')));
// app.use(express.static(path.join(__dirname, '../fe/Public')));
app.use(
helmet({
contentSecurityPolicy: false,
})
);
app.use(
session({
secret: '123456789',
resave: false,
saveUninitialized: false,
cookie: {
secure: false,
httpOnly: false,
},
})
);
app.use(
cors({
origin: 'http://localhost:5500',
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],
credentials: true,
})
);
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.use('/api/v1', userRoutes);
app.use('/api/v1/posts', postsRoutes);
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});