43 lines
948 B
TypeScript
43 lines
948 B
TypeScript
import * as express from 'express';
|
|
import router from './routes';
|
|
import * as dotenv from "dotenv";
|
|
dotenv.config({ quiet: true });
|
|
|
|
const app = express();
|
|
|
|
const swaggerJsdocOpts = {
|
|
failOnErrors: true,
|
|
definition: {
|
|
openapi: '3.0.0',
|
|
info: {
|
|
title: 'kittyurl',
|
|
version: '0.0.1'
|
|
}
|
|
},
|
|
apis: ['./src/routes/*.ts']
|
|
};
|
|
const swaggerUi = require('swagger-ui-express');
|
|
const swaggerJsdoc = require('swagger-jsdoc');
|
|
const swaggerSpec = swaggerJsdoc(swaggerJsdocOpts);
|
|
|
|
app.use(express.json());
|
|
app.use(router);
|
|
if (process.env.DEBUG === "true") {
|
|
app.use('/swagger', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
|
|
}
|
|
|
|
// Handle 404s
|
|
// https://stackoverflow.com/a/9802006
|
|
app.use(function(req, res) {
|
|
res.status(404);
|
|
|
|
if (req.accepts('json')) {
|
|
res.json({ status: 'error', error: 'Not found' });
|
|
return;
|
|
}
|
|
|
|
res.type('txt').send('Not found');
|
|
});
|
|
app.listen(6567, () => console.log('(HTTP Server) Listening on port 6567.'));
|
|
|