Skip to content

Commit eabe08e

Browse files
Remove the need for node
1 parent e5a047e commit eabe08e

File tree

20 files changed

+89
-225
lines changed

20 files changed

+89
-225
lines changed

cli/cli.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
$database = ENV['DB_DATABASE'] || settings['database']['dbname'].to_s
1414

1515
class RubyCLI < Thor
16+
desc "start", "Start the server"
17+
option :node, :type => :boolean
18+
def start
19+
if options[:node]
20+
puts "Starting with node server...".red
21+
system("node nodeJS/server.js --node-port=9294 &")
22+
system("bundle exec puma -e production -q")
23+
else
24+
puts "Starting the server...".red
25+
system("bundle exec puma -e production -q")
26+
end
27+
end
1628
desc "create", "Create a new user"
1729
def create
1830
puts "Creating a new user...".red

config/puma.rb

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,31 @@
11
require 'etc'
22
require 'os'
33
require 'colorize'
4-
# get the ruby Implementation
4+
55
if OS.windows?
66
puts "You are using Windows. Not multi-threading...".colorize(:red)
77
puts "Starting Server...".colorize(:green)
8-
rubyPort = 9292
9-
rubyPort = ARGV[ARGV.index('-p') + 1] || ARGV[ARGV.index('--port') + 1] if ARGV.include?('-p') || ARGV.include?('--port')
10-
if ENV['RACK_ENV'] == 'production'
11-
system("node node-server/server.js --ruby-port=#{rubyPort} --node-port=9293 &")
12-
else
13-
system("node node-server/server-dev.js --ruby-port=#{rubyPort} --node-port=9293 &")
14-
end
158
elsif ENV['WP'] != nil
169
workers ENV['WP'].to_i
1710
before_fork do
1811
puts "The amount of proccesses is: #{ENV['WP']}".colorize(:green)
1912
puts "Master Process ID: #{Process.pid}".colorize(:green)
2013
puts "Starting Server...".colorize(:green)
21-
rubyPort = 9292
2214
cpuCount = Etc.nprocessors
23-
rubyPort = ARGV[ARGV.index('-p') + 1] || ARGV[ARGV.index('--port') + 1] if ARGV.include?('-p') || ARGV.include?('--port')
24-
if ENV['RACK_ENV'] == 'production'
25-
system("node node-server/server.js --ruby-port=#{rubyPort} --node-port=9293 &")
26-
else
27-
system("node node-server/server-dev.js --ruby-port=#{rubyPort} --node-port=9293 &")
28-
end
2915
end
3016
else
3117
if RUBY_ENGINE != 'jruby' && RUBY_ENGINE != 'truffleruby'
3218
workers Etc.nprocessors
3319
before_fork do
3420
puts "Master Process ID: #{Process.pid}".colorize(:green)
3521
puts "Starting Server...".colorize(:green)
36-
rubyPort = 9292
3722
cpuCount = Etc.nprocessors
38-
rubyPort = ARGV[ARGV.index('-p') + 1] || ARGV[ARGV.index('--port') + 1] if ARGV.include?('-p') || ARGV.include?('--port')
39-
if ENV['RACK_ENV'] == 'production'
40-
system("node node-server/server.js --ruby-port=#{rubyPort} --node-port=9293 &")
41-
else
42-
system("node node-server/server-dev.js --ruby-port=#{rubyPort} --node-port=9293 &")
43-
end
4423
end
4524
else
4625
puts "You are using JRuby or TruffleRuby. Not using workers...".colorize(:red)
4726
puts "Starting Server...".colorize(:green)
48-
rubyPort = 9292
49-
rubyPort = ARGV[ARGV.index('-p') + 1] || ARGV[ARGV.index('--port') + 1] if ARGV.include?('-p') || ARGV.include?('--port')
50-
if ENV['RACK_ENV'] == 'production'
51-
system("node node-server/server.js --ruby-port=#{rubyPort} --node-port=9293 &")
52-
else
53-
system("node node-server/server-dev.js --ruby-port=#{rubyPort} --node-port=9293 &")
54-
end
5527
end
5628
end
5729

5830
preload_app!
59-
port ENV['PORT'] || 9292
31+
port ENV['PORT'] || 9293

docker/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ RUN cp config/settings.example.yml config/settings.yml
1616
VOLUME /usr/src/app/config/
1717
# Run the app
1818
EXPOSE 9293
19-
CMD ["pnpm", "start"]
19+
CMD ["pnpm", "start", "--node"]
2020

2121
FROM node:latest as jruby
2222
WORKDIR /usr/src/app
@@ -40,7 +40,7 @@ RUN cp config/settings.example.yml config/settings.yml
4040
VOLUME /usr/src/app/config/
4141
# Run the app
4242
EXPOSE 9293
43-
CMD ["pnpm", "start"]
43+
CMD ["pnpm", "start", "--node"]
4444

4545
FROM ghcr.io/graalvm/truffleruby-community:23.1.2-debian as truffleruby
4646
WORKDIR /usr/src/app
@@ -59,4 +59,4 @@ RUN cp config/settings.example.yml config/settings.yml
5959
VOLUME /usr/src/app/config/
6060
# Run the app
6161
EXPOSE 9293
62-
CMD ["pnpm", "start"]
62+
CMD ["pnpm", "start", "--node"]

main.rb

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
logging = false
2525
end
2626
set :logging, logging
27-
set :show_exceptions, logging
27+
set :show_exceptions, logging
2828
set :components, File.join(settings.root, 'src', 'views', 'components')
2929
cookie_options = {
3030
:key => 'UserAllowed',
@@ -34,6 +34,7 @@
3434
:secure => true,
3535
:httponly => true
3636
}
37+
3738
#Validate the YML file
3839
validateYML()
3940
#Validate the ENV variables
@@ -83,15 +84,33 @@
8384

8485
mime_type :wasm, 'application/wasm'
8586

87+
latestRelease = getLatestRelease()
88+
8689
# Other routes
87-
get '/rubyHealth/?' do
88-
return "OK"
90+
get '/health/?' do
91+
return { status: "ok" }.to_json
8992
end
9093

9194
get '/:unlock?' do
9295
erb :index, :layout => :"layouts/index"
9396
end
9497

98+
get '/version/?' do
99+
return { version: latestRelease }.to_json
100+
end
101+
102+
use Rack::ReverseProxy do
103+
reverse_proxy /^\/gms(\/.*)$/, 'https://rawcdn.githack.com/$1'
104+
end
105+
106+
get '/search/:q?' do
107+
content_type :json
108+
query = params[:q]
109+
resp = HTTParty.get("https://search.brave.com/api/suggest?q=#{query}&format=json")
110+
return resp.body
111+
end
112+
113+
95114
#Auth to login to the site
96115
post '/auth' do
97116
if Settings.corlink.enabled == "true" && Settings.private == "false"

node-server/server-dev.js

Lines changed: 0 additions & 108 deletions
This file was deleted.

node-server/version.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

node-server/compile.js renamed to nodeJS/compile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ async function compile() {
1616
}
1717
await logger(compileSCSS(), 'Compiling SCSS');
1818
}
19-
export default compile;
19+
compile();
20+
//export default compile;
Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,25 @@
11
import Fastify from 'fastify';
22
import fastifyMiddie from '@fastify/middie';
33
import fastifyHttpProxy from '@fastify/http-proxy';
4-
import { fileURLToPath } from 'node:url';
54
import { createBareServer } from '@tomphttp/bare-server-node';
65
import createRammerhead from "rammerhead/src/server/index.js";
76
import { createServer } from 'http';
8-
import fs from 'fs'
9-
import YAML from 'yaml';
107
import path from 'path';
118
const __dirname = path.resolve();
12-
const settings = YAML.parse(fs.readFileSync(path.join(__dirname, '/config/settings.yml'), 'utf8'));
139
import chalk from 'chalk';
14-
import compile from './compile.js';
15-
import getLatestRelease from './version.js';
1610
import wisp from 'wisp-server-node';
1711
import fastifyCaching from '@fastify/caching';
18-
let rubyPort = process.argv.find((arg) => arg.startsWith('--ruby-port')).split('=')[1] || 9292;
19-
let nodePort = process.argv.find((arg) => arg.startsWith('--node-port')).split('=')[1] || 9293;
20-
21-
const latestRelease = await getLatestRelease();
12+
let nodePort = process.argv.find((arg) => arg.startsWith('--node-port')).split('=')[1] || 9294;
2213
const bare = createBareServer('/bare/');
2314
const rh = createRammerhead();
2415
const rammerheadScopes = [ "/rammerhead.js", "/hammerhead.js", "/transport-worker.js", "/task.js", "/iframe-task.js", "/worker-hammerhead.js", "/messaging", "/sessionexists", "/deletesession", "/newsession", "/editsession", "/needpassword", "/syncLocalStorage", "/api/shuffleDict", "/mainport" ];
2516
const rammerheadSession = /^\/[a-z0-9]{32}/;
2617
function shouldRouteRh(req) {
2718
const url = new URL(req.url, "http://0.0.0.0");
28-
return (rammerheadScopes.includes(url.pathname) || rammerheadSession.test(url.pathname));
19+
return (rammerheadScopes.includes("/rammer/" + url.pathname) || rammerheadSession.test("/rammer/" + url.pathname));
2920
}
3021
function routeRhRequest(req, res) { rh.emit("request", req, res) }
3122
function routeRhUpgrade(req, socket, head) { rh.emit("upgrade", req, socket, head) }
32-
console.log(chalk.red('Compiling...'))
33-
compile();
3423

3524
const proxyHandler = (handler, opts) => {
3625
return createServer().on('request', (req, res) => {
@@ -63,7 +52,7 @@ await app
6352
privacy: fastifyCaching.privacy.NOCACHE
6453
})
6554
.register(fastifyHttpProxy, {
66-
upstream: 'http://localhost:9292',
55+
upstream: 'http://localhost:9293',
6756
prefix: '/',
6857
http2: false,
6958
replyOptions: {
@@ -74,34 +63,7 @@ await app
7463
}
7564
}
7665
})
77-
.register(fastifyHttpProxy, {
78-
upstream: 'https://rawcdn.githack.com',
79-
prefix: '/gms/',
80-
http2: false,
81-
})
8266
.register(fastifyMiddie)
83-
app.get('/search=:query', async (req, res) => {
84-
const { query } = req.params;
85-
try {
86-
const resp = await fetch(`https://search.brave.com/api/suggest?q=${query}&format=json`).then((res) => res.json());
87-
res.send(resp);
88-
}
89-
catch (err) {
90-
reply.code(500).send({ error: "Internal Server Error" });
91-
}
92-
});
93-
app.get('/version', (req, res) => {
94-
res.send({ version: latestRelease });
95-
});
96-
app.get('/health', async (req, res) => {
97-
let resp = await fetch(`http://localhost:${rubyPort}/rubyHealth`);
98-
if (resp.status === 200) {
99-
res.send({ status: 'ok' });
100-
}
101-
else {
102-
res.send({ status: 'error' });
103-
}
104-
});
10567

10668
app.listen({ port: nodePort, host: '0.0.0.0' });
107-
console.log(chalk.green(`Server listening on port ${chalk.red(nodePort)}`));
69+
console.log(chalk.green(`NodeJS Server listening on port ${chalk.red(nodePort)}`));

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
"author": "Ruby Network",
77
"scripts": {
88
"preinstall": "npx -y only-allow pnpm",
9-
"dev": "bundle exec rerun --ignore 'src/public/css/*' --signal 'TERM' -c -w 5 --no-notify -- puma",
10-
"start": "bundle exec puma -e production",
9+
"dev": "bundle exec rerun --ignore 'src/public/css/*' --ignore 'node_modules/*' --signal 'TERM' -c -w 5 --no-notify -- puma",
10+
"start": "bundle exec ruby cli/cli.rb start",
1111
"install": "pnpm run build && bundle install",
1212
"build:rh": "tsc -p ./rammerhead/tsconfig.json",
1313
"build:epoxytransport": "cd ./epoxytransport/ && npm run build",
14-
"build": "pnpm run build:rh && pnpm run build:epoxytransport",
14+
"build:css": "node ./nodeJS/compile.js",
15+
"build": "pnpm run build:rh && pnpm run build:epoxytransport && pnpm run build:css",
1516
"cli": "bundle exec ruby ./cli/cli.rb"
1617
},
1718
"engines": {
@@ -31,7 +32,7 @@
3132
"chalk": "^5.3.0",
3233
"fastify": "^4.26.2",
3334
"progress-estimator": "^0.3.1",
34-
"rammerhead": "https://github.com/Ruby-Network/rammerhead/releases/download/v1/rammerhead-2.tgz",
35+
"rammerhead": "https://github.com/Ruby-Network/rammerhead/releases/download/v1.0.5/rammerhead-1.2.41-ruby.1.tgz",
3536
"sass": "^1.71.1",
3637
"terser": "^5.29.2",
3738
"typescript": "^5.4.2",

0 commit comments

Comments
 (0)