30 lines
798 B
JavaScript
30 lines
798 B
JavaScript
|
var express = require('express');
|
||
|
var path = require('path');
|
||
|
var cookieParser = require('cookie-parser');
|
||
|
var logger = require('morgan');
|
||
|
|
||
|
var apiRouter = require('./routes/api');
|
||
|
|
||
|
var app = express();
|
||
|
|
||
|
// view engine setup
|
||
|
app.set('views', path.join(__dirname, 'views'));
|
||
|
|
||
|
// app.use(logger('dev'));
|
||
|
app.use(express.json());
|
||
|
app.use(express.urlencoded({extended: false}));
|
||
|
app.use(cookieParser());
|
||
|
app.use(express.static(path.join(__dirname, 'web')));
|
||
|
|
||
|
// enable CORS
|
||
|
app.use(function (req, res, next) {
|
||
|
res.header('Access-Control-Allow-Origin', '*');
|
||
|
res.header("Access-Control-Allow-Methods", "GET, PUT, POST, DELETE");
|
||
|
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
|
||
|
next();
|
||
|
});
|
||
|
|
||
|
app.use('/api', apiRouter);
|
||
|
|
||
|
module.exports = app;
|