Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

Did add a route '/roms', which sends a list of roms from server folde… #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</div>
<div class="select">
<select name="rom">
<option value="falling">falling</option>
<!-- <option value="falling">falling</option>
<option value="dushlan">dushlan</option>
<option value="color_test">color_test</option>
<option value="firedemo">firedemo</option>
Expand All @@ -61,6 +61,7 @@
<option value="giko017">giko017</option>
<option value="hello">hello</option>
<option value="nestest">nestest</option>
<option value="Mario">Mario</option> -->
</select>
</div>
</div>
Expand All @@ -84,6 +85,17 @@
<script type="module" src="./init.js"></script>
<script type="module">
import {start, startFile} from './main.js';
function romsListRender( roms ){
document.querySelector('select').innerHTML = roms.map( rom => `<option value=${rom}>${rom}</option>` ).join('');
}
(async ()=>{
const req = await fetch('/roms');
if( req.ok ){
let roms = await req.json();
roms = roms.map( rom => rom.split('.')[0] );
romsListRender(roms);
}
})();
document.querySelector('select')
.addEventListener('change', (e) => {
start(`./roms/${e.target.value}.nes`);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"dev": "nodemon server.js",
"start": "npm run connect",
"connect": "node server.js",
"test": "echo \"Error: no test specified\" && exit 1",
Expand Down
17 changes: 16 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
var connect = require('connect'),
serveStatic = require('serve-static');
path = require('path');
fs = require('fs');

var app = connect();

app.use(serveStatic(__dirname));
app.use('/roms', function(req, res, next){
if( req.method === 'GET' ){
fs.readdir(path.join(__dirname, 'roms'), 'utf-8' , function(err, files){
if( err ){
console.log(err);
} else{
let roms = files.filter( file => /.+?\.nes$/.test(file) );
res.end(JSON.stringify(roms));
}
next();
});
}
});
app.listen(3334);

console.log('open localhost:3334');
console.log('open http://localhost:3334/');