-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
149 lines (118 loc) · 3.8 KB
/
Copy pathindex.js
File metadata and controls
149 lines (118 loc) · 3.8 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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// const cookieParser = require('cookie-parser');
// const multer = require('multer');
// const logger = require('morgan');
// const bodyParser = require('body-parser');
// const favicon = require('serve-favicon');
//const path = require('path');
//const express = require('express');
//const nlpRouter = require('./public/assets/js/nlp');
import cookieParser from "cookie-parser";
import multer from "multer";
import logger from "morgan";
import bodyParser from "body-parser";
import favicon from "serve-favicon";
import path from "path";
import fs from "fs";
import KioskBoard from 'kioskboard';
import i18n from "i18n-express";
import i18next from "i18next";
import Backend from "i18next-http-backend";
import i18nextMiddleware, { LanguageDetector } from "i18next-express-middleware";
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
import express from "express";
const port = process.env.PORT || 3000;
const app = express();
// View engine setup
// Set EJS as the template engine
// app.set('view engine', 'ejs');
// app.set('views', path.join(__dirname, 'views'));
// app.use(session({
// secret: 'secret',
// saveUnitialized: true,
// resave: true
// }));
// app.use(i18n({
// translationsPath: path.join(__dirname, 'i18n'),
// siteLangs: ["es", "en"],
// textsVarName: 'translation'
// }));
// app.use('/', indexRoutes);
// parse requests of content-type - application/json
app.use(express.json());
// parse requests of content-type - application/x-www-form-urlencoded
app.use(express.urlencoded({ extended: true }));
// Serve static assets from node_modules
// app.use('/scripts', express.static(path.join(__dirname, '/node_modules/')));
// Serve static assets from public/assets
// app.use(express.static('node_modules'));
app.use(express.static('public/assets'));
// Logger
// create a write stream (in append mode)
var accessLogStream = fs.createWriteStream(path.join(__dirname, 'access.log'), { flags: 'a' });
// setup the logger
//app.use(logger('dev'));
app.use(logger('combined', { stream: accessLogStream }));
export {accessLogStream};
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
//app.use('/api/nlp', nlpRouter);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(favicon('./public/assets/favicon.ico'));
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'public/index.html'));
});
app.use(express.static("public"));
// app.use(express.json({ limit: "1mb" }));
app.post("/api", (request, response) => {
console.log("I got a request!");
console.log(request.body);
const data = request.body;
response.json(data);
});
// 404 PAGE
app.use(function(req, res, next){
res.status(404).sendFile(path.join(__dirname, 'public/404_page.html'));
});
// KioskBoard.run('.js-kioskboard-input', {
// // ...init options
// });
// // Initialize i18next and add middleware
// i18next
// .use(Backend)
// .init({
// lang: 'es',
// resources: {
// en: {
// translation: enTranslations,
// },
// es: {
// translation: esTranslations,
// },
// },
// });
// app.use(i18nextMiddleware.handle(i18next));
// // Middleware to inject the `t` function into res.locals
// app.use((req, res, next) => {
// res.locals.t = req.t;
// next();
// });
// app.get('/index', (req, res) => {
// res.render('index');
// });
// // LANGUAGE SWITCHING
// app.get('/change-language/:lng', (req, res) => {
// const { lng } = req.params;
// req.i18n.changeLanguage(lng);
// res.redirect('/');
// });
// app.listen(port, () => {
// console.log(`App listening at http://localhost:${port}`);
// });
app.listen(3000, '0.0.0.0', function() {
console.log('Listening to port: ' + 3000);
});
//module.exports = app;
export {app};