2021-10-06 09:43:59 +00:00
|
|
|
import Hapi = require('@hapi/hapi');
|
2021-10-07 06:15:35 +00:00
|
|
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
2021-10-06 15:38:01 +00:00
|
|
|
const Exiting = require('exiting');
|
2021-10-07 06:15:35 +00:00
|
|
|
import Path = require('path');
|
2021-10-06 09:43:59 +00:00
|
|
|
import { handleAlbum, handleGallery, handleMedia, handleTag, handleUser } from './handlers';
|
|
|
|
|
|
|
|
import CONFIG from './config';
|
|
|
|
|
2021-10-06 15:38:01 +00:00
|
|
|
const server = Hapi.server({
|
|
|
|
port: CONFIG.port,
|
|
|
|
host: CONFIG.host,
|
|
|
|
address: CONFIG.address,
|
|
|
|
routes: {
|
|
|
|
files: {
|
|
|
|
relativeTo: Path.join(__dirname, 'static')
|
2021-10-06 09:43:59 +00:00
|
|
|
}
|
2021-10-07 17:22:21 +00:00
|
|
|
},
|
|
|
|
debug: {
|
|
|
|
request: ['error']
|
|
|
|
},
|
2021-10-06 15:38:01 +00:00
|
|
|
});
|
|
|
|
server.events.on('stop', () => {
|
|
|
|
console.log('Server stopped.');
|
|
|
|
});
|
|
|
|
|
|
|
|
const manager = Exiting.createManager(server);
|
|
|
|
|
|
|
|
const init = async () => {
|
2021-10-06 09:43:59 +00:00
|
|
|
await server.register(require('@hapi/vision'));
|
|
|
|
await server.register(require('@hapi/inert'));
|
|
|
|
|
|
|
|
server.route({
|
|
|
|
method: 'GET',
|
|
|
|
path: '/css/{param*}',
|
|
|
|
handler: ({
|
2021-10-07 06:15:35 +00:00
|
|
|
directory: {
|
|
|
|
path: Path.join(__dirname, 'static/css')
|
|
|
|
}
|
|
|
|
} as any) // eslint-disable-line @typescript-eslint/no-explicit-any
|
2021-10-06 09:43:59 +00:00
|
|
|
});
|
|
|
|
server.views({
|
|
|
|
engines: {
|
|
|
|
pug: require('pug')
|
|
|
|
},
|
|
|
|
relativeTo: __dirname,
|
|
|
|
path: 'templates',
|
|
|
|
});
|
|
|
|
server.route({
|
|
|
|
method: 'GET',
|
|
|
|
path: '/{baseName}.{extension}',
|
|
|
|
handler: handleMedia,
|
|
|
|
});
|
|
|
|
server.route({
|
|
|
|
method: 'GET',
|
|
|
|
path: '/a/{albumID?}',
|
|
|
|
handler: handleAlbum,
|
|
|
|
});
|
|
|
|
server.route({
|
|
|
|
method: 'GET',
|
|
|
|
path: '/t/{tagID?}',
|
|
|
|
handler: handleTag,
|
|
|
|
});
|
|
|
|
server.route({
|
|
|
|
method: 'GET',
|
|
|
|
path: '/user/{userID?}',
|
|
|
|
handler: handleUser,
|
|
|
|
});
|
|
|
|
server.route({
|
|
|
|
method: 'GET',
|
|
|
|
path: '/gallery/{galleryID}',
|
|
|
|
handler: handleGallery,
|
|
|
|
});
|
|
|
|
|
2021-10-06 15:38:01 +00:00
|
|
|
await manager.start();
|
2021-10-06 09:43:59 +00:00
|
|
|
console.log('Server running on %s', server.info.uri);
|
|
|
|
};
|
|
|
|
|
|
|
|
process.on('unhandledRejection', (err) => {
|
|
|
|
console.error(err);
|
|
|
|
process.exit(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
init();
|