Spaces:
Sleeping
Sleeping
File size: 876 Bytes
2161081 d255781 2161081 d255781 2161081 d255781 2161081 d255781 2161081 d255781 2161081 d255781 2161081 |
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 |
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var cors = require('cors');
var indexRouter = require('./routes/index'); // This should correctly import the routes
var app = express();
// Enable CORS
var corsOptions = {
origin: '*'
};
app.use(cors(corsOptions));
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')));
app.use('/', indexRouter); // This ensures /talk works
// Error handling
app.use(function (req, res, next) {
res.status(404).json({ error: "Not Found" });
});
app.use(function (err, req, res, next) {
console.error(err.stack);
res.status(500).json({ error: err.message || "Internal Server Error" });
});
module.exports = app;
|