switch to go

This commit is contained in:
XenGi 2023-10-19 17:58:36 +02:00
parent 31ec2917ea
commit 0f34300a8a
Signed by: xengi
SSH key fingerprint: SHA256:EvLbWxFCtfmd+8Xa6RkzkhIga+wFkKCekfFacYVn63M
7 changed files with 4 additions and 116 deletions

View file

@ -1,40 +0,0 @@
# use the official Bun image
# see all versions at https://hub.docker.com/r/oven/bun/tags
FROM docker.io/oven/bun:1 as base
WORKDIR /usr/src/app
# install dependencies into temp directory
# this will cache them and speed up future builds
FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json bun.lockb /temp/dev/
RUN cd /temp/dev && bun install --frozen-lockfile
# install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY package.json bun.lockb /temp/prod/
RUN cd /temp/prod && bun install --frozen-lockfile --production
# copy node_modules from temp directory
# then copy all (non-ignored) project files into the image
FROM install AS prerelease
COPY --from=install /temp/dev/node_modules node_modules
COPY . .
# [optional] tests & build
ENV NODE_ENV=production
RUN bun test
RUN bun run build
# copy production dependencies and source code into final image
FROM base AS release
COPY --from=install /temp/prod/node_modules node_modules
COPY --from=prerelease /usr/src/app/index.ts .
COPY --from=prerelease /usr/src/app/package.json .
# run the app
USER bun
EXPOSE 8000/tcp
EXPOSE 8080/tcp
ENTRYPOINT [ "bun", "run", "index.ts" ]

BIN
bun.lockb

Binary file not shown.

View file

@ -10,7 +10,7 @@
in {
devShells.default = pkgs.mkShell {
packages = with pkgs; [
bun
go
mpd
mpc-cli
];

3
go.mod Normal file
View file

@ -0,0 +1,3 @@
module github.com/cccb/sanic
go 1.20

View file

@ -1,21 +0,0 @@
{
"name": "sanic",
"module": "server.ts",
"type": "module",
"scripts": {
"start": "bun run server.ts",
"init": "mkdir -p /tmp/sanic/{music,playlists}; touch /tmp/sanic/mpd_db",
"mpd": "mpd --no-daemon ./mpd.conf",
"docker-build": "docker build --pull -t sanic .",
"docker-run": "docker run -it --rm -p 8000:8000 -p 8080:8080 sanic"
},
"devDependencies": {
"bun-types": "latest"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"react": "^18.2.0"
}
}

View file

@ -1,32 +0,0 @@
// Run websocket server
const wsServer = Bun.serve({
port: 8080,
fetch(req, server) {
// upgrade the request to a WebSocket
if (server.upgrade(req)) {
return; // do not return a Response
}
return new Response("Upgrade failed :(", { status: 500 });
},
websocket: {
message(ws, message) { // a message is received
ws.send(message); // echo back the message
},
open(ws) {}, // a socket is opened
close(ws, code, message) {}, // a socket is closed
drain(ws) {}, // the socket is ready to receive more data
},
});
// Run web server
const webServer = Bun.serve({
port: 8000,
//unix: "/run/sanic.sock",
fetch(req) {
return new Response("Put frontend here!");
},
});
console.log(`Listening on http://localhost:${webServer.port} ...`);
console.log(`Listening on ws://localhost:${wsServer.port} ...`);

View file

@ -1,22 +0,0 @@
{
"compilerOptions": {
"lib": ["ESNext"],
"module": "esnext",
"target": "esnext",
"moduleResolution": "bundler",
"moduleDetection": "force",
"allowImportingTsExtensions": true,
"noEmit": true,
"composite": true,
"strict": true,
"downlevelIteration": true,
"skipLibCheck": true,
"jsx": "react-jsx",
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"allowJs": true,
"types": [
"bun-types" // add Bun global
]
}
}