feat: insecure HTTP

This commit is contained in:
cha0s 2024-06-29 06:28:27 -05:00
parent 221666783d
commit a53be624d3
3 changed files with 7 additions and 4 deletions

View File

@ -8,6 +8,8 @@ import {getSession} from '@/session.server.js';
import Engine from './engine.js';
const isInsecure = process.env.SILPHIUS_INSECURE_HTTP;
const wss = new WebSocketServer({
noServer: true,
});
@ -50,7 +52,7 @@ class SocketServer extends Server {
}
async readAsset(path) {
const url = new URL(path, 'https://localhost:3000')
if ('production' === process.env.NODE_ENV) {
if (isInsecure) {
url.protocol = 'http:';
}
return fetch(url.href).then((response) => (

View File

@ -7,7 +7,7 @@
"build": "remix vite:build",
"dev": "NODE_OPTIONS=--use-openssl-ca node ./server.js",
"lint": "eslint --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint .",
"start": "cross-env NODE_ENV=production NODE_OPTIONS=--use-openssl-ca npm run dev",
"start": "cross-env NODE_ENV=production npm run dev",
"storybook": "storybook dev -p 6006",
"storybook:build": "storybook build",
"test": "vitest app"

View File

@ -4,11 +4,12 @@ import express from 'express';
import morgan from 'morgan';
const isProduction = process.env.NODE_ENV === 'production';
const isInsecure = process.env.SILPHIUS_INSECURE_HTTP;
const app = express();
let server;
if (isProduction) {
if (isInsecure) {
const {createServer} = await import('node:http');
server = createServer(app);
}
@ -84,5 +85,5 @@ app.all('*', remixHandler);
const port = process.env.PORT || 3000;
server.listen(port, () =>
console.log(`Express server listening at http${isProduction ? '' : 's'}://localhost:${port}`)
console.log(`Express server listening at http${isInsecure ? '' : 's'}://localhost:${port}`)
);