Fix docker-entrypoint.sh arguments and don't require specifying an IP address in servers

This commit is contained in:
Samuel Elliott 2022-03-18 09:10:52 +00:00
parent 056bb1edd6
commit cc8dbc6f6e
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
3 changed files with 23 additions and 9 deletions

View File

@ -2,4 +2,4 @@
mkdir -p /data/android
exec /app/bin/nxapi.js --data-path /data $@
exec /app/bin/nxapi.js --data-path /data "$@"

View File

@ -76,7 +76,11 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
app.post('/api/znca/f', bodyParser.json(), async (req, res) => {
try {
console.log('Received request from %s, port %d', req.socket.remoteAddress, req.socket.remotePort);
console.log('[%s] %s %s HTTP/%s from %s, port %d%s, %s',
new Date(), req.method, req.url, req.httpVersion,
req.socket.remoteAddress, req.socket.remotePort,
req.headers['x-forwarded-for'] ? ', ' + req.headers['x-forwarded-for'] : '',
req.headers['user-agent']);
await ready;
const data: {
@ -127,10 +131,10 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
});
for (const address of argv.listen) {
const match = address.match(/^(?:((?:\d+\.){3}\d+)|\[(.*)\]):(\d+)$/);
if (!match || !net.isIP(match[1] || match[2])) throw new Error('Not a valid address/port');
const match = address.match(/^((?:((?:\d+\.){3}\d+)|\[(.*)\]):)(\d+)$/);
if (!match || (match[1] && !net.isIP(match[2] || match[3]))) throw new Error('Not a valid address/port');
const server = app.listen(parseInt(match[3]), match[1] || match[2]);
const server = app.listen(parseInt(match[4]), match[2] || match[3] || '::');
server.on('listening', () => {
const address = server.address() as net.AddressInfo;
console.log('Listening on %s, port %d', address.address, address.port);

View File

@ -17,7 +17,7 @@ declare global {
}
}
const debug = createDebug('cli:http-server');
const debug = createDebug('cli:nso:http-server');
export const command = 'http-server';
export const desc = 'Starts a HTTP server to access the Nintendo Switch Online app API';
@ -47,6 +47,16 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
const app = express();
app.use('/api/znc', (req, res, next) => {
console.log('[%s] %s %s HTTP/%s from %s, port %d%s, %s',
new Date(), req.method, req.url, req.httpVersion,
req.socket.remoteAddress, req.socket.remotePort,
req.headers['x-forwarded-for'] ? ', ' + req.headers['x-forwarded-for'] : '',
req.headers['user-agent']);
next();
});
const localAuth: express.RequestHandler = async (req, res, next) => {
if (argv.requireToken || !req.query.user) return next();
@ -311,10 +321,10 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
});
for (const address of argv.listen) {
const match = address.match(/^(?:((?:\d+\.){3}\d+)|\[(.*)\]):(\d+)$/);
if (!match || !net.isIP(match[1] || match[2])) throw new Error('Not a valid address/port');
const match = address.match(/^((?:((?:\d+\.){3}\d+)|\[(.*)\]):)(\d+)$/);
if (!match || (match[1] && !net.isIP(match[2] || match[3]))) throw new Error('Not a valid address/port');
const server = app.listen(parseInt(match[3]), match[1] || match[2]);
const server = app.listen(parseInt(match[4]), match[2] || match[3] || '::');
server.on('listening', () => {
const address = server.address() as net.AddressInfo;
console.log('Listening on %s, port %d', address.address, address.port);