-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.ts
More file actions
67 lines (54 loc) · 1.95 KB
/
Copy pathapp.ts
File metadata and controls
67 lines (54 loc) · 1.95 KB
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
import createHttpError from 'http-errors';
import express from 'express';
import { Request, Response, NextFunction } from 'express';
import path from 'path';
import cookieParser from 'cookie-parser';
import logger, { token } from 'morgan';
import cors from 'cors';
// Routes
import { router as authsRouter } from './app/contollers/auths';
const app = express();
// -------------------------------------------
// App Config
// -------------------------------------------
app.set('views', path.join(__dirname, '/app/views'));
app.set('view engine', 'ejs');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
// -------------------------------------------
// CORS Config
// -------------------------------------------
// // Add a list of allowed origins.
// // If you have more origins you would like to add, you can add them to the array below.
// const allowedOrigins = ['http://127.0.0.1:5173', 'http://localhost:5173'];
// const options: cors.CorsOptions = {
// origin: allowedOrigins,
// credentials: true,
// };
// // Then pass these options to cors:
// app.use(cors(options));
app.use(cors()); // CORS-enabled for all origins
// -------------------------------------------
// Routing
// -------------------------------------------
app.use('/auths', authsRouter);
// -------------------------------------------
// Server Config
// -------------------------------------------
app.use((req: Request, res: Response, next: NextFunction) =>
next(createHttpError(404))
);
app.use((err: any, req: Request, res: Response, next: NextFunction) => {
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
res.status(err.status || 500);
res.render('error');
});
const port = 4100;
app.listen(port, () => {
console.log(`start express server => http://localhost:${port}`)
});
module.exports = app;