Git Product home page Git Product logo

bare-server-node's Introduction

TOMP Bare Server

This repository implements the TompHTTP bare server. See the specification here.

Upgrading

A guide for updating from v1 to v2 can be found here.

Usage

We provide a command-line interface for creating a server.

For more features, specify the --help option when running the CLI.

Quickstart

  1. Install Bare Server Node globally
npm install --global @tomphttp/bare-server-node
  1. Start the server
npx bare-server-node

Optionally start the server localhost:8080:

npx bare-server-node --port 8080 --host localhost

Programically create a bare server

See examples/.

Development

See the wiki.

bare-server-node's People

Contributors

caracal-js avatar countbleck avatar e9x avatar s-tn avatar velzie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bare-server-node's Issues

Not work

Error: Cannot find module './dist/cli.js'
when run on debian 12 vps

Imported module not found

index.mjs

import Server from "@tomphttp/bare-server-node";

package.json

{
  "dependencies": {
    "@tomphttp/bare-server-node": "github:tomphttp/bare-server-node"
  }
}

console

> node index.mjs

node:internal/errors:464
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '\node_modules\@tomphttp\bare-server-node\dist\BareServer.esm.js' imported from \index.mjs
    at new NodeError (node:internal/errors:371:5)
    at finalizeResolution (node:internal/modules/esm/resolve:394:11)
    at moduleResolve (node:internal/modules/esm/resolve:944:10)
    at defaultResolve (node:internal/modules/esm/resolve:1041:11)
    at ESMLoader.resolve (node:internal/modules/esm/loader:530:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:251:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:79:40)
    at link (node:internal/modules/esm/module_job:78:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Need help ASAP

I'm making a game website with node.js (im using the fastify lib)

const fastify = require('fastify')({ logger: false });
const fs = require('fs').promises;  // Using promises for async/await
const path = require('path');
const { createBareServer } = require('@tomphttp/bare-server-node');

const bareServer = createBareServer('/bare/');

const readTemplateFile = async (filePath) => {
    try {
        const content = await fs.readFile(filePath, 'utf-8');
        return content;
    } catch (err) {
        console.error(`Error reading file ${filePath}:`, err);
        return '';
    }
};

fastify.register(require('@fastify/static'), {
    root: path.join(__dirname, 'static'),
    prefix: '/', // optional: default '/'
})

const replaceContent = (fileData, meta, navbar) => {
    return fileData.replace('<head>', meta + '<head>').replace('<body>', `<body> ${navbar}`);
};

(async () => {
    const navbar = await readTemplateFile(path.join(__dirname, './templates/navbar.html'));
    const meta = await readTemplateFile(path.join(__dirname, './templates/meta.html'));

    try {
        const files = await fs.readdir('./pages');
        for (const file of files) {
            const filePath = path.join(__dirname, './pages', file);
            let fileData = await readTemplateFile(filePath);
            fileData = fileData.replace('</head>', '\t' + meta + '\n</head>').replace('<body>', '<body>\n\t' + navbar);
            fastify.get(`/${file.split('.')[0] === 'index' ? '' : file.split('.')[0]}`, (req, res) => {
                if (bareServer.shouldRoute(req)) {
                    bareServer.routeUpgrade(req, socket, head)
                } else { res.status(200).type('text/html').send(fileData) }
            });
        }

        fastify.listen({ port: 3000 }, (err, address) => {
            if (err) {
                fastify.log.error(err);
                process.exit(1);
            }
        });
    } catch (err) {
        console.error('Error reading pages directory:', err);
    }
})();

When I go to /bare/ it shows this: {"message":"Route GET:/bare/ not found","error":"Not Found","statusCode":404}

Help

Not Working on Gitpod

It returns a status code of 401

When trying to go to a page it returns:

RangeError: Failed to construct 'Response': The status provided (0) is outside the range [200, 599].

ipaddr.js issue

Something broke... Error: ipaddr: the address has neither IPv6 nor IPv4 format
at ipaddr.parse (/node_modules/ipaddr.js/lib/ipaddr.js:929:19)
at GetAddrInfoReqWrap.callback (/node_modules/@tomphttp/bare-server-node/dist/createServer.js:35:50)
at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:131:8)
at GetAddrInfoReqWrap.callbackTrampoline (node:internal/async_hooks:130:17)

Change LICENSE to LGPL, MPL, or a permissive license

A strongly copyleft license like the GPL prevents permissively licensed projects from "linking against" bare-server-node.

At the same time, since bare-server-node uses the GPL (and not the AGPL), network use is thankfully not distribution. This means a GPL-licensed server/backend using bare-server-node does not need to disclose its source to the public. It will need to disclose its source to whoever deploys it, however.

Using MPL or LGPL would allow bare-server-node to be used in proprietary projects while still ensuring modifications to bare-server-node are disclosed upon distribution. A permissive license would additionally allow modifications to bare-server-node to be proprietary, which might also be desired.

The end goal of this issue is to allow proprietary or permissively-licensed backends/servers to use bare-server-node without needing to be licensed under the GPL.

Weird Google Sign-In Bug

So Recently I've tried on Ultraviolet and Dynamic to sign into my school google account to test something and well it gave an error so I asked around in the dynamic discord since the issue also persists on dynamic and greenydev said that its an issue with Bare so I have brought this issue over here. The error I was encountering is as seen below:
image

Information:
Browser: Microsoft Edge 115
Bare-Server-Node Version: (v2.0.0)
Ultraviolet Bare: v3
Dynamic Bare: v2

package-lock.json's "fedora:4873" messing up installation

attempting to run npm install github:tomphttp/bare-server-node causes an error because of local settings

npm ERR! code ENOTFOUND
npm ERR! syscall getaddrinfo
npm ERR! errno ENOTFOUND
npm ERR! network request to http://fedora:4873/yallist/-/yallist-4.0.0.tgz failed, reason: getaddrinfo ENOTFOUND fedora
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network 
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

my suggestion is deleting the package-lock.json file or npm installing it on a machine that doesn't have settings that don't work on another's

gives error even though i did everything

NotFoundError: Not Found\n at Server.routeRequest (/opt/render/project/src/node_modules/@tomphttp/bare-server-node/src/BareServer.ts:237:11)\n at Server. (/opt/render/project/src/node_modules/@tomphttp/bare-server-node/src/cli.ts:106:17)\n at Server.emit (node:events:518:28)\n at parserOnIncoming (node:_http_server:1137:12)\n at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17)

A widely used Cloudflare deployment appears inoperable

I've been trying to use both the "holyuboffical.net" and "hypertabs.cc" proxy services for about a week now, and neither seems to be able to connect to the server. "uv.holyuboffical.net", "rh.holyuboffical.net", and "uv.hypertabs.cc" all say that the server they're trying to access is down. I don't know what the structure is for these services, but the fact that two different services and two different proxies are all inoperative due to a faulty server (according to the Cloudflare error page) suggests this is not an issue with the individual services.

Steps to reproduce:

  • Enter a URL into "holyubofficial.net" or "hypertabs.cc" and observe the resulting error
  • (Optional) Change the proxy used by "holyubofficial.net" in the settings, then repeat the above step
  • (Optional) Enter "uv.holyuboffical.net", "rh.holyubofficial.net", or "uv.hypertabs.cc" into your search engine's search bar (Google, Firefox, Bing, etc.)

Screenshots available on request.

When running index.js

node:internal/modules/esm/resolve:215
const resolvedOption = FSLegacyMainResolve(packageJsonUrlString, packageConfig.main, baseStringified);
^

Error: Cannot find package '/workspaces/omega/node_modules/@tomphttp/bare-server-node/package.json' imported from /workspaces/omega/index.js
at legacyMainResolve (node:internal/modules/esm/resolve:215:26)
at packageResolve (node:internal/modules/esm/resolve:841:14)
at moduleResolve (node:internal/modules/esm/resolve:927:18)
at defaultResolve (node:internal/modules/esm/resolve:1169:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:227:38)
at ModuleWrap. (node:internal/modules/esm/module_job:87:39)
at link (node:internal/modules/esm/module_job:86:36) {
code: 'ERR_MODULE_NOT_FOUND'
}
this happens

How can I build a bare server like uv-node?

Is there a way to build only bare-server without uv-static using heroku, Vercel, VPS server, etc.? Or are you planning to reflect the bare-server-v2 you are probably developing in uv or incognito?

How to change system language

When I deploy on a server in Japan, access to Google and everything is in Japanese, and when I deploy in the United States, Google searches are in English, how do I specify the language without judging by the location of the server?

Security leak with LAN addresses

Users can access localhost and LAN addresses like 127.0.0.1 and 10.0.0.0/8.
This allows them to access server internal without any restrictions.

Unknown errors causing super slow response times to requests

Errors I recieve
AbortError: The operation was aborted
at EventTarget.onAbort (node:internal/streams/add-abort-signal:37:20)
at [nodejs.internal.kHybridDispatch] (node:internal/event_target:735:20)
at EventTarget.dispatchEvent (node:internal/event_target:677:26)
at abortSignal (node:internal/abort_controller:308:10)
at AbortController.abort (node:internal/abort_controller:338:5)
at ServerResponse. (/var/www/bareserver/node_modules/@tomphttp/bare-server-node/dist/V1.js:136:15)
... 3 lines matching cause stack trace ...
at Socket.emit (node:events:525:35) {
code: 'ABORT_ERR',
[cause]: DOMException [AbortError]: This operation was aborted
at new DOMException (node:internal/per_context/domexception:53:5)
at AbortController.abort (node:internal/abort_controller:336:18)
at ServerResponse. (/var/www/bareserver/node_modules/@tomphttp/bare-server-node/dist/V1.js:136:15)
at ServerResponse.emit (node:events:513:28)
at emitCloseNT (node:_http_server:965:10)
at Socket.onServerResponseClose (node:_http_server:277:5)
at Socket.emit (node:events:525:35)
at TCP. (node:net:322:12)
}

Code:

import createBareServer from "@tomphttp/bare-server-node";
import http from "node:http";

const httpServer = http.createServer();
const bareServer = createBareServer("/bare/", {logErrors: true});

httpServer.on("request", (req, res) => {
    if (bareServer.shouldRoute(req)) {
      bareServer.routeRequest(req, res);
    } else {
        res.writeHead(404).end();
    }
  });
  httpServer.on("upgrade", (req, socket, head) => {
    if (bareServer.shouldRoute(req)) {
      bareServer.routeUpgrade(req, socket, head);
    } else {
      socket.end();
      //return;
    }
  });


  httpServer.on("listening", () => {
    console.log('listening on http://localhost:${8081}/');
  });
  
  httpServer.listen({
    port: 8081
  });

Node Version: v18.15.0
Bare-Server-Node Version: v1.2.5

Help

I started it on localhost:8080 but i dont know where to deploy it too

Rewriting binary WebSocket packets to text

Apologies in advance if I've arrived at the wrong place. I am the developer of Worlds FRVR (https://worlds.frvr.com/). It appears some users are trying to play it via what appears to be a proxy at https://artclass.site/ which brought me to their support, who said they use this project for their HTTP rewriting, so I thought I'd pass the error along here. Users are unable to play (and it's causing various errors we're noticing) due to the proxy turning binary WebSocket packets into text WebSocket packets (and losing information along the way). Feel free to close if there's nothing you can do about this, I'm just passing along the issue =).

I need help.

Hello, I am a 13 year old student wanting to deploy a proxy to unblock websites that my school blocks. I have forked nebula proxy, and in the uv config I need to change the bare:"/bare/" to an actual bare server in order to make it a static website. My question is how would I host this so I get a url to put in?

Instalation error.

Greetings. I try to install it on replit by running npm install --global @tomphttp/bare-server-node and also with npm install in this repo (on a cloned instance) it seems that it gives lots of errors that, in this case, could tell that dependencies instalation has failed. In the log, it says that bare-server-node is not found in npm registry when running npx bare-server-node
Please, fix this as soon as possible (if you have time) so I can fix my bare server
Also, as an alternative (i prefer this solution), I would like you to look into my repo GeneralMathsMOD so you can help me to fix package-lock.json and package.json so I can implement my bare automatically without creating a remote bare server (as I prefer it locally inside the repo). Something Fails in my bare server instalation inside that repository This part has been fixed :)
Thank you so much.
Hope you can solve this issue.
Greetings from:
ModdedStuffGuy

Issue with ipaddr

The "ipaddr.js" dependency can crash the app.

The issue is, sometimes "string" is actually an array of objects.
Screen Shot 2023-05-22 at 5 50 51 PM

I've currently fixed it by adding the following line to the module:

        if (typeof string === 'object') string = string[0].address;

However, I'm looking for a more permanent solution.
Screen Shot 2023-05-22 at 5 53 35 PM

Not sure if this is an installation error.
I'm using the latest version of this, and am using this package as it is required for Ultraviolet deployment.

Error: Unable to fetch Bare meta: 404 Not Found

const Koa = require('koa');const app = new Koa();
const port = 80;
const http = require('node:https')
const createBareServer = require('@tomphttp/bare-server-node');
const colors = require('./colors.js');
var logger = require('koa-logger');
const sendfile = require('koa-sendfile')
const bare = createBareServer('/bare/')

app.on('request', (req, res) => {
    if (bare.shouldRoute(req)) {
        bare.routeRequest(req, res)
    } else {
        app(req, res)
    }
})
app.on("error", err => console.log(err));
app.on('upgrade', (req, socket, head) => {
    if (bare.shouldRoute(req)) {
        bare.routeUpgrade(req, socket, head)
    } else {
        socket.end()
    }
});

I am using Koa.js to try and update my backend, and this code works with Express. It shows the following error in inspect element:

uv.sw.js:1 Error: Unable to fetch Bare meta: 404 Not Found
    at Sh (BareClient.ts:132:9)
    at async Ih.request (BareClient.ts:230:3)
    at async Ih.fetch (BareClient.ts:364:10)
    at async s.fetch (uv.sw.js:1:1725)

If I try and change app to httpsServer, it shows "Cannot set headers after they are sent to the client.` in the terminal, instead of inspect element.

const options = {
	key: key,
	cert: cert
}
const httpsServer = https.createServer(options, app.callback()); // adds koa.js app to https server
const bare = createBareServer('/bare/')

httpsServer.on('request', (req, res) => {
    if (bare.shouldRoute(req)) {
        bare.routeRequest(req, res)
    } else {
        app(req, res)
    }
})
httpsServer.on("error", err => console.log(err));
httpsServer.on('upgrade', (req, socket, head) => {
    if (bare.shouldRoute(req)) {
        bare.routeUpgrade(req, socket, head)
    } else {
        socket.end()
    }
});
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at new NodeError (node:internal/errors:393:5)
    at ServerResponse.setHeader (node:_http_outgoing:644:11)
    at writeResponse (C:\Users\shuttle\Downloads\shuttle test\node_modules\@tomphttp\bare-server-node\dist\AbstractMessage.js:46:13)
    at Server.routeRequest (C:\Users\shuttle\Downloads\shuttle test\node_modules\@tomphttp\bare-server-node\dist\BareServer.js:163:48)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 'ERR_HTTP_HEADERS_SENT'
}

Is Koa.js not supported or am I doing something wrong? Tell me if you need more information

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.