32 lines
782 B
JavaScript
32 lines
782 B
JavaScript
import fs from 'fs';
|
|
import path from 'path';
|
|
import cors from 'cors';
|
|
import logger from 'morgan';
|
|
import express from 'express';
|
|
|
|
import { log } from './modules/log.js';
|
|
import { speedLimiter, checkSystemLoad } from './modules/requestHandler.js';
|
|
|
|
import testRouter from './routes/test';
|
|
|
|
const app = express();
|
|
app.set('trust proxy', 1);
|
|
|
|
app.use(express.json());
|
|
app.use(logger('dev'));
|
|
app.use(speedLimiter);
|
|
app.use(checkSystemLoad);
|
|
app.use(logger('combined', { stream: fs.createWriteStream(path.join(__dirname, 'logs/access.log'), { flags: 'a' }) }));
|
|
app.use(cors({
|
|
origin: '*',
|
|
}));
|
|
|
|
app.use(express.static('public'));
|
|
|
|
// routes
|
|
app.use('/api/test', testRouter);
|
|
|
|
// run the API
|
|
app.listen(process.env.PORT, async () => {
|
|
log(`running at port ${process.env.PORT}`);
|
|
}); |