mirror of
https://gitlab.com/nekoya/web.git
synced 2024-11-14 02:16:19 +01:00
44 lines
No EOL
1 KiB
JavaScript
44 lines
No EOL
1 KiB
JavaScript
var express = require("express");
|
|
var cookieParser = require("cookie-parser");
|
|
var logger = require("morgan");
|
|
var bodyParser = require("body-parser");
|
|
|
|
const app = express();
|
|
|
|
const indexRouter = require('./routes/index');
|
|
const api = require('./routes/api');
|
|
|
|
let config;
|
|
try {
|
|
config = require("./config");
|
|
} catch (e) {
|
|
console.log("No config file found");
|
|
process.exit(0);
|
|
}
|
|
|
|
app.use(express.static("public"));
|
|
app.set("view engine", "ejs");
|
|
|
|
app.use(bodyParser.urlencoded({ extended: true }));
|
|
app.use(bodyParser.json());
|
|
app.use(logger("dev"));
|
|
app.use(express.json());
|
|
app.use(express.urlencoded({ extended: false }));
|
|
app.use(cookieParser());
|
|
|
|
app.use('/', indexRouter);
|
|
app.use('/api', api);
|
|
|
|
app.use(function (req, res, next) {
|
|
res.header("Access-Control-Allow-Origin", "*");
|
|
res.header(
|
|
"Access-Control-Allow-Headers",
|
|
"Origin, X-Requested-With, Content-Type, Accept"
|
|
);
|
|
next();
|
|
});
|
|
|
|
app.listen(config.port, () => {
|
|
console.log(`Server is running on port : ${config.port}`);
|
|
});
|
|
module.exports = app; |