You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.4 KiB
TypeScript

import * as dotenv from "dotenv";
import cors from 'cors';
import express from "express";
import { sequelize } from "./sequelize";
import { IndexRouter } from "./controllers/v0/index.router";
import bodyParser from "body-parser";
import { V0_FEED_MODELS, V0_USER_MODELS } from "./controllers/v0/model.index";
(async () => {
dotenv.config();
await sequelize.addModels(V0_FEED_MODELS);
await sequelize.addModels(V0_USER_MODELS);
await sequelize.sync();
console.log("Database Connected");
const app = express();
const port = process.env.PORT || 8080;
app.use(bodyParser.json());
// app.use(cors());
// We set the CORS origin to * so that we don't need to
// worry about the complexities of CORS.
app.use(cors({
"allowedHeaders": [
'Origin', 'X-Requested-With',
'Content-Type', 'Accept',
'X-Access-Token', 'Authorization', 'Access-Control-Allow-Origin',
'Access-Control-Allow-Headers',
'Access-Control-Allow-Methods'
],
"methods": 'GET,HEAD,OPTIONS,PUT,PATCH,POST,DELETE',
"preflightContinue": true,
"origin": '*',
}));
app.use("/api/v0/", IndexRouter);
// Root URI call
app.get("/", async (req, res) => {
res.send("/api/v0/");
});
// Start the Server
app.listen(port, () => {
console.log(`Backend server is listening on port ${port}....`);
console.log(`Frontent server running ${process.env.URL}`);
console.log(`press CTRL+C to stop server`);
});
})();