34 lines
954 B
TypeScript
34 lines
954 B
TypeScript
import { Encryptor } from "./encryptor";
|
|
import { readFileSync } from "fs";
|
|
import * as path from "path";
|
|
import express from "express";
|
|
import { api } from "./api";
|
|
|
|
const config = JSON.parse(readFileSync(path.join(process.cwd(), "config.json"), "utf8")) as {
|
|
PORT: number;
|
|
VALIDATOR_STRING: string;
|
|
};
|
|
|
|
Encryptor.setMagic(config.VALIDATOR_STRING);
|
|
|
|
const app = express();
|
|
|
|
app.disable('x-powered-by');
|
|
app.use(express.static("build"));
|
|
app.use((req, res, next) => {
|
|
res.header('Access-Control-Allow-Origin', '*');
|
|
res.header('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE,OPTIONS');
|
|
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
if (req.method === 'OPTIONS') {
|
|
return res.sendStatus(204); // Respond to preflight requests
|
|
}
|
|
next();
|
|
});
|
|
|
|
|
|
app.use("/api", api);
|
|
|
|
app.listen(config.PORT, () => {
|
|
console.log(`Listening to ${config.PORT}`);
|
|
});
|