-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
56 lines (42 loc) · 1.29 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
import createError from 'http-errors';
import express from 'express';
import path from 'path';
import logger from 'morgan'
import {subscribeEnpoints,configRequestTypes} from './routes/endpoint.conf.js'
import { fileURLToPath } from 'url';
import dotenv from 'dotenv'
import i18next from 'i18next'
import i18nextMiddleware from 'i18next-http-middleware'
import Backend from 'i18next-fs-backend'
var app = express();
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
dotenv.config();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(logger('dev'));
configRequestTypes(app)
app.use(express.static(path.join(__dirname, 'public')));
i18next
.use(Backend)
.use(i18nextMiddleware.LanguageDetector)
.init({
backend: {
loadPath: __dirname + '/public/locales/{{lng}}.json'
},
fallbackLng: 'en',
preload: ['en','tr']
})
app.use(i18nextMiddleware.handle(i18next))
subscribeEnpoints(app)
// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});
// error handler
app.use(function(err, req, res, next) {
res.locals.error = req.app.get('env') === 'development' ? err : {};
res.status(err.status || 500).json({message:err.message});
});
export default app;