mirror of
https://github.com/engineer-man/piston.git
synced 2025-06-07 18:56:26 +02:00
lint like rest of codebase
This commit is contained in:
parent
1b7504a191
commit
b3be57e0b4
10 changed files with 1893 additions and 1864 deletions
114
api/src/index.js
114
api/src/index.js
|
@ -14,77 +14,77 @@ const logger = Logger.create('index');
|
|||
const app = express();
|
||||
|
||||
(async () => {
|
||||
logger.info('Setting loglevel to', config.log_level);
|
||||
Logger.setLogLevel(config.log_level);
|
||||
logger.debug('Ensuring data directories exist');
|
||||
logger.info('Setting loglevel to', config.log_level);
|
||||
Logger.setLogLevel(config.log_level);
|
||||
logger.debug('Ensuring data directories exist');
|
||||
|
||||
Object.values(globals.data_directories).for_each((dir) => {
|
||||
let data_path = path.join(config.data_directory, dir);
|
||||
Object.values(globals.data_directories).for_each(dir => {
|
||||
let data_path = path.join(config.data_directory, dir);
|
||||
|
||||
logger.debug(`Ensuring ${data_path} exists`);
|
||||
logger.debug(`Ensuring ${data_path} exists`);
|
||||
|
||||
if (!fss.exists_sync(data_path)) {
|
||||
logger.info(`${data_path} does not exist.. Creating..`);
|
||||
if (!fss.exists_sync(data_path)) {
|
||||
logger.info(`${data_path} does not exist.. Creating..`);
|
||||
|
||||
try {
|
||||
fss.mkdir_sync(data_path);
|
||||
} catch (e) {
|
||||
logger.error(`Failed to create ${data_path}: `, e.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
try {
|
||||
fss.mkdir_sync(data_path);
|
||||
} catch (e) {
|
||||
logger.error(`Failed to create ${data_path}: `, e.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
logger.info('Loading packages');
|
||||
const pkgdir = path.join(
|
||||
config.data_directory,
|
||||
globals.data_directories.packages
|
||||
);
|
||||
|
||||
const pkglist = await fs.readdir(pkgdir);
|
||||
|
||||
const languages = await Promise.all(
|
||||
pkglist.map((lang) => {
|
||||
return fs.readdir(path.join(pkgdir, lang)).then((x) => {
|
||||
return x.map((y) => path.join(pkgdir, lang, y));
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
const installed_languages = languages
|
||||
.flat()
|
||||
.filter((pkg) =>
|
||||
fss.exists_sync(path.join(pkg, globals.pkg_installed_file))
|
||||
logger.info('Loading packages');
|
||||
const pkgdir = path.join(
|
||||
config.data_directory,
|
||||
globals.data_directories.packages
|
||||
);
|
||||
|
||||
installed_languages.for_each((pkg) => runtime.load_package(pkg));
|
||||
const pkglist = await fs.readdir(pkgdir);
|
||||
|
||||
logger.info('Starting API Server');
|
||||
logger.debug('Constructing Express App');
|
||||
logger.debug('Registering middleware');
|
||||
const languages = await Promise.all(
|
||||
pkglist.map(lang => {
|
||||
return fs.readdir(path.join(pkgdir, lang)).then(x => {
|
||||
return x.map(y => path.join(pkgdir, lang, y));
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
app.use(body_parser.urlencoded({ extended: true }));
|
||||
app.use(body_parser.json());
|
||||
const installed_languages = languages
|
||||
.flat()
|
||||
.filter(pkg =>
|
||||
fss.exists_sync(path.join(pkg, globals.pkg_installed_file))
|
||||
);
|
||||
|
||||
app.use((err, req, res, next) => {
|
||||
return res.status(400).send({
|
||||
stack: err.stack,
|
||||
installed_languages.for_each(pkg => runtime.load_package(pkg));
|
||||
|
||||
logger.info('Starting API Server');
|
||||
logger.debug('Constructing Express App');
|
||||
logger.debug('Registering middleware');
|
||||
|
||||
app.use(body_parser.urlencoded({ extended: true }));
|
||||
app.use(body_parser.json());
|
||||
|
||||
app.use((err, req, res, next) => {
|
||||
return res.status(400).send({
|
||||
stack: err.stack,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
logger.debug('Registering Routes');
|
||||
logger.debug('Registering Routes');
|
||||
|
||||
const api_v2 = require('./api/v2');
|
||||
app.use('/api/v2', api_v2);
|
||||
app.use('/api/v2', api_v2);
|
||||
const api_v2 = require('./api/v2');
|
||||
app.use('/api/v2', api_v2);
|
||||
app.use('/api/v2', api_v2);
|
||||
|
||||
app.use((req, res, next) => {
|
||||
return res.status(404).send({ message: 'Not Found' });
|
||||
});
|
||||
app.use((req, res, next) => {
|
||||
return res.status(404).send({ message: 'Not Found' });
|
||||
});
|
||||
|
||||
logger.debug('Calling app.listen');
|
||||
const [address, port] = config.bind_address.split(':');
|
||||
logger.debug('Calling app.listen');
|
||||
const [address, port] = config.bind_address.split(':');
|
||||
|
||||
app.listen(port, address, () => {
|
||||
logger.info('API server started on', config.bind_address);
|
||||
});
|
||||
app.listen(port, address, () => {
|
||||
logger.info('API server started on', config.bind_address);
|
||||
});
|
||||
})();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue