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

56 lines
1.3 KiB

12 months ago
/**
* Main program of Hero Union of filesite.io
**/
import express from 'express';
import bodyParser from 'body-parser';
12 months ago
import apiRouter from './router_api.mjs';
12 months ago
const app = express();
//Express behind proxies
app.set('trust proxy', true);
app.disable('x-powered-by');
//Serving static files
app.use(express.static('public'));
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
12 months ago
app.use('/api', apiRouter);
12 months ago
app.get('/', (req, res) => {
return res.send('Welcome to Hero Union of filesite.io');
});
8 months ago
app.post('/test', (req, res) => {
console.log('Post data got in /test', req.body);
return res.status(200).send('Done');
});
12 months ago
//error handler
app.use((err, req, res, next) => {
if (res.headersSent) {
return next(err);
}
console.error('Request error in hero union: %s', err.stack);
12 months ago
var statusCode = 500;
if (typeof(err.statusCode) != 'undefined' && err.statusCode) {
statusCode = err.statusCode;
}
return res.status(statusCode).send(err.message);
})
// Listen to the App Engine-specified port, or 8080 otherwise
const PORT = process.env.PORT || 8080;
8 months ago
const HOST = '127.0.0.1';
app.listen(PORT, HOST, async () => {
12 months ago
console.log('Server listening on port %s...', PORT);
});