Nathan13888 / CodeRunnerBot

Smart Discord Bot that runs almost any code of any supported language. Powered by Go and engineer-man/piston. Runs on Docker and code execution network could be distributed.
GNU General Public License v3.0
5 stars 2 forks source link

Piston Wrapper library (milindmadhukar/go-piston) for Go has issues with locally hosted Piston API #9

Open Nathan13888 opened 2 years ago

Nathan13888 commented 2 years ago

Latest version contains our own implementation of the .../execute endpoint since whatever those go-bindings library that was recommended doesn't include the content-type header.

Without this header, there is an error in one of the middleware components of the Piston API. Not sure why this doesn't effect the public Piston API.

router.use((req, res, next) => {
    if (['GET', 'HEAD', 'OPTIONS'].includes(req.method)) {
        return next();
    }

    if (!req.headers['content-type'].startsWith('application/json')) {
        return res.status(415).send({
            message: 'requests must be of type application/json',
        });
    }

    next();
});

The current "custom" implementation of the Piston API endpoints seems more reliable to me. Perhaps this should later be refactored to its own package such as piston-wrapper for reuse in the future.

Refer to exec.go for how the implementation works.

vidhanio commented 2 years ago

Maybe try leaving a comment on the official piston asking if the prod server they have just handles it or something? It could be them handling it on the main server.

HexF commented 2 years ago

We have a proxy server in front removing access to the package manager endpoints, so the Content-Type header is ignored.